0

I'm following this tutorial and cant for the life of me figure out why webpack isn't recognizing JSX? Would love someone to point out the silly thing that i'm missing :)

my full code here https://github.com/dukarc/django-react-app

Error:

\django-react-app\leadmanager\frontend\src\components\App.js: Unexpected token (6:11)

  4 | class App extends Component {
  5 |   render() {
> 6 |     return <h1>React App</h1>;
    |            ^
  7 |   }
  8 | }
  • Things I have Tried

    1. rm -rf node_modules && rm -f package-lock.json && npm install
    2. refered back to the tutorial github and double checked that i'm in sync
  • Versions (will output more if requested ... this was just off top of my head):

    • node: 10.15.1
    • npm: 6.8.0

package.json

{
  "name": "lead_manager_react_django",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development  ./leadmanager/frontend/src/index.js --output ./leadmanager/frontend/static/frontend/main.js",
    "build": "webpack --mode production ./leadmanager/frontend/src/index.js --output ./leadmanager/frontend/static/frontend/main.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.2.2",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.5",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "webpack": "^4.29.0",
    "webpack-cli": "^3.2.1"
  },
  "dependencies": {
    "prop-types": "^15.6.2",
    "react": "^16.7.0",
    "react-dom": "^16.7.0"
  }
}

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
};

.babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "plugins": ["transform-class-properties"]
}
0

1 Answer 1

3

I checked out your source code, it had a small typo, its getElementById instead of getElementByID.

Its line 10 in the following file

https://github.com/dukarc/django-react-app/blob/master/leadmanager/frontend/src/components/App.js

It works post that correction for me.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Johnny! That was a small typo ... Per you being able to get it to work ... I ended up just cloning my repo in a new folder and trying again ... seems to be working now ... I still have no idea why the old stuff wasn't working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.