React Webpack3:您可能需要一个合适的加载程序来处理此文件类型



我正试图使用Webpack3和Babel来编译ES6资产,但我收到了一个错误"您可能需要一个合适的加载程序来处理这个文件类型。"下面是我收到的确切错误:

ERROR in ./node_modules/use-global-hook/index.js
Module parse failed: Unexpected token (2:18)
You may need an appropriate loader to handle this file type.
| function setState(store, newState, afterUpdateCallback) {
|   store.state = { ...store.state, ...newState };
|   store.listeners.forEach((listener) => {
|     listener.run(store.state);
@ ./src/components/dynamicLabel/store/index.js 11:21-47
@ ./src/components/dynamicLabel/components/dynamicLabel.js
@ ./src/components/dynamicLabel/index.js

以下是我的webpack.config.js的样子:

const path = require('path');
module.exports = {
devtool: 'source-map',
entry: {
csvparse: './src/components/csvparse',
dateTime: './src/components/dateTime',
gmoment: './src/components/gmoment',
dynamicLabel: './src/components/dynamicLabel',
gvideo: './src/components/gvideo',
stickyScroll: './src/components/stickyScroll',
webAccessibility: './src/components/webAccessibility'
},
output: {
path: path.resolve(__dirname, 'lib'),
filename: '[name]/index.js',
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['.js', '.jsx','.less']
},
module: {
rules: [
{
test: /.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /.(?:le|c)ss$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1
}
},
{
loader: require.resolve('less-loader'),
options: {
importLoaders: 1
}
}
]
}
]
},
externals: {
'react': 'commonjs react'
}
};

这是我的包.json:中的babel对象部分

"babel": {
"presets": [
"es2015",
"stage-2",
"react"
],
"plugins": [
[
"transform-runtime",
{
"regenerator": true
}
]
]
},

有人能帮我解决这个问题吗?

提前谢谢。

尝试使用@babel/plugin提议类属性

相关内容

  • 没有找到相关文章

最新更新