React.js:如何修复语法错误:React.js中的意外令牌<

时间:2019-01-25 15:33:23

标签: javascript json reactjs webpack package.json

React.js->语法错误:意外的令牌,我似乎找不到解决方案,我的所有(.babelrc)预设,webpack.config和package.json似乎都是正确的。

过去1周,我一直在坚持这一点,但我找不到问题,请帮助我是初学者

分别是我的webpack.config.js,package.json和.babelrc

webpack.config.js:-我已经检查了一下,似乎无法发现问题,是否必须创建更多的装载程序或其他东西,请帮助我

const WEBPACK = require('webpack');
const PATH = require('path');

module.exports = {
mode: "none",
resolve: {
    extensions: ['.js', '.jsx']
},
context: __dirname,
entry: {
    app: ['./src/index.jsx'], 
},
output : {
    path: PATH.join(__dirname, '/MY_FOLDER_OUTPUT'),
    filename: 'bundle.js'
},
module: {
    rules: [
        {
            test: /\.jsx$/,
            exclude: /node_modules/,
            loader: "babel-loader",
        }
    ]
},

};

package.json

{
  "name": "newReact",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "babel": "babel",
    "webpack": "webpack",
    "build": "webpack-dev-server --mode development --open",
    "prod_build": "webpack --mode production",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/preset-react": "^7.0.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.0.15",
    "copy-webpack-plugin": "^4.6.0",
    "es6-promise": "^4.2.5",
    "extract-text-webpack-plugin": "^3.0.2",
    "html-webpack-plugin": "^3.2.0",
    "react": "^16.7.0",
    "react-dom": "^16.7.0"
  },
  "devDependencies": {
    "@babel/core": "^7.2.2",
    "@babel/preset-env": "^7.2.3",
    "@babel/preset-stage-0": "^7.0.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.5",
    "babel-preset-es2015": "^6.24.1",
    "webpack": "^4.29.0",
    "webpack-cli": "^3.2.1"
  }
}

babelrc

{
    "presets": ["es2015","react"],
   "plugins": ["transform-react-jsx"]
}

这是index.jsx

import React from "react"
import ReactDOM from "react-dom"

ReactDOM.render(
      <h1>
        Hello World
      </h1>,
      document.getElementById('app')
);

0 个答案:

没有答案