简体   繁体   English

React似乎无法识别我的.js中的'='符号

[英]React doesn't seem to recognize the '=' symbol in my .js

I'm facing an issue while trying to get a react app to work. 我在尝试使React应用正常工作时遇到问题。 When compiling using babel, it seems that the '=' symbol in my .js file isn't recognized...And it returns me "Uncaught Error: Module build failed: SyntaxError". 使用babel进行编译时,似乎无法识别我的.js文件中的'='符号...并且它返回我“未捕获的错误:模块构建失败:SyntaxError”。 I don't know how to solve this issue and it's really beginning to get on my nerves :) . 我不知道如何解决这个问题,这真的开始引起我的紧张:)。 Here's my webpack.config.js 这是我的webpack.config.js

const path = require('path');

module.exports = {
entry: ['babel-polyfill', './lib/main.js'],
output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname)
},
devtool: 'source-map',
module: {
    rules: [
        {
            test: /\.js$/,
            exclude: /(node_modules|bower_components)/,
            use: {
                loader: 'babel-loader',
            }
        }
    ]
}
};    

Here's the beginning of my main.js 这是我的main.js的开始

import React from 'react';
import ReactDOM from 'react-dom';
import _ from 'lodash';


const createArray = (size) => Array.from({ length: size }, (_, i) => i);

class Cell extends React.Component {
backgroundColor = () => {

And my index.html 还有我的index.html

<!doctype html>
<head>
  <meta charset="utf-8">
  <title>Memory Game</title>
  <!-- certainly some style rules here -->
 <link rel="stylesheet" href="../style.css"/>
</head>
<body>
  <div id="react"> Loading...</div>
  <script src="bundle.js"></script>
</body>
</html>

Thanks in advance, and please, keep in mind that I'm a beginner :) Have a nice evening! 在此先感谢您,请记住我是初学者:)祝您晚上愉快!

module: {
    rules: [
        {
            test: /\.jsx?$/,
            exclude: /(node_modules|bower_components)/,
            loader: 'babel-loader',
            query: {
                presets: ['react', 'es2015'],
                plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy']
            }
        }
    ]
}

With the appropriate modules: 使用适当的模块:

"babel-plugin-react-html-attrs"
"babel-plugin-transform-class-properties"
"babel-plugin-transform-decorators-legacy"
"babel-preset-es2015"
"babel-preset-react"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM