将webpack从升级^1.14.0
到后,我收到 JSX 解析错误"^3.0.0"
ERROR in ./shared/Application.js
Module parse failed: /Users/arjunkumar/Documents/Work/test/web/shared/Application.js Unexpected token (25:2)
You may need an appropriate loader to handle this file type.
中的相关代码Application.js
如下所示
ReactDOM.render(
<Provider store={store}>
<Router routes={Routes(store)} history={history} />
</Provider>,
document.getElementById('app-shell')
);
文件的相关部分webpack.config.js
如下所示(所有必需的插件都正确导入到 webpack 配置文件中,以下代码中不存在)。
module.exports = {
entry: {
app:['./shared/Application.js'],
vendors:[// vendors like react and other libs ]
},
output: {
path: __dirname + '/public/build',
filename: 'app.[chunkhash].js'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
rules: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
'autoprefixer-loader',
'sass-loader'
],
exclude: /node_modules/
}),
},
{
test: /\.js$/,
exclude: [/node_modules/],
use:[{
loader: 'babel-loader',
options: {
presets: [
['es2015', {modules: false}],
'react'
],
babelrc: false
}
}]
},
{
test: /\.jsx$/,
exclude: [/node_modules/],
use:[{
loader: 'babel-loader',
options: {
presets: [
'es2015',
'react'
],
babelrc: false
}
}]
},
]
},
devtool: ( process.env.NODE_ENV === 'production' ) ? false : 'eval',
plugins: [
new ExtractTextPlugin(
'app.[chunkhash].css',
{
allChunks: true
}
),
new webpack.optimize.CommonsChunkPlugin({
names: ['utilities','vendors'],
filename: '[name].[chunkhash].js',
minChunks: Infinity
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
},
output: {
comments:false
},
comments: false
}),
new AssetsPlugin({
filename: 'assets.json',
fullPath: false,
path: __dirname + '/public/build',
prettyPrint: true
})
]
};
来自文件的问题的相关依赖关系package.json
如下。
{
"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-plugin-transform-react-constant-elements": "^6.9.1",
"babel-plugin-transform-react-inline-elements": "^6.8.0",
"babel-plugin-transform-react-remove-prop-types": "^0.2.9",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-loose": "^8.0.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"extract-text-webpack-plugin": "^2.1.2",
"html-webpack-plugin": "^2.21.0",
"husky": "^0.13.1",
"lodash-webpack-plugin": "^0.10.6",
"node-sass": "^3.13.1",
"postcss-loader": "^2.0.6",
"purifycss-webpack": "^0.4.2",
"sass-loader": "^4.1.1",
"webpack": "^3.0.0",
"webpack-bundle-analyzer": "^2.3.0",
"webpack-dev-server": "^2.5.0"
},
"dependencies": {
"react": "^15.1.0"
}
}
以防万一有人想检查.babelrc
文件(我认为babel-loader
尊重babelrc: false
标志webpack.config.js
)。
{
"presets": [
"es2015",
"react",
"stage-0"
],
"env": {
"production": {
"plugins": [
"transform-react-constant-elements",
"transform-react-inline-elements",
"transform-react-remove-prop-types"
]
}
},
"comments": false,
"compact": false
}
关于可能出错的任何想法或线索?
我注意到的另一件重要的事情是,即使我的 webpack 项目和全局依赖项位于3.0.0
,当我在项目中运行 webpack 时,它显示Version: webpack 1.15.0
在顶部。截图如下。