gpt4 book ai didi

javascript - reactjs 意外 token '<'

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:54:50 27 4
gpt4 key购买 nike

我用 react-redux、redux 创建了 reactjs 应用程序。启动 reactjs 项目时,在索引文件的第 13 行出现意外标记错误。索引文件如下。

ERROR in ./src/index.js
Module build failed: SyntaxError: D:/Reactjs_work/
/src/index.js: Unexpected token (13:2)

11 |
12 | ReactDOM.render(
> 13 | <Provider store={createStoreWithMiddleware(reducers)}>
| ^
14 | <App />
15 | </Provider>
16 | , document.querySelector('.container'));

@ multi main
webpack: Failed to compile.

以下是index.js文件

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';

import App from './components/app';
import reducers from './reducers';

const createStoreWithMiddleware = applyMiddleware()(createStore);

ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>
, document.querySelector('.container'));

我在这里完成了以下主题。但没有成功。 Reactjs: Unexpected token '<' Error ReactJS Syntax Error: Unexpected Token

webpack.config.js

module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel'
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};

最佳答案

用以下代码替换模块

module: {
loaders: [{
test: /\.(js|jsx)?$/,
exclude: /node_modules/,
loader: 'babel-loader',

query: {
presets: ['es2015', 'react']
}
}]
},

关于javascript - reactjs 意外 token '<',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47109795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com