簡體   English   中英

React似乎無法識別我的.js中的'='符號

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

我在嘗試使React應用正常工作時遇到問題。 使用babel進行編譯時,似乎無法識別我的.js文件中的'='符號...並且它返回我“未捕獲的錯誤:模塊構建失敗:SyntaxError”。 我不知道如何解決這個問題,這真的開始引起我的緊張:)。 這是我的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',
            }
        }
    ]
}
};    

這是我的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 = () => {

還有我的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>

在此先感謝您,請記住我是初學者:)祝您晚上愉快!

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']
            }
        }
    ]
}

使用適當的模塊:

"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