我正在尝试配置我的第一个 Node react 应用程序。
我不断收到“无法解析 babel-loader”的错误消息。
谷歌搜索该错误,我发现了一些不起作用的建议。
首先是在我的webpack.config.js中添加以下内容
// resolveLoader: {
// modulesDirectories: '/usr/local/lib/node_modules'
// },
尝试会产生错误提示:
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.resolveLoader has an unknown property 'modulesDirectories'. These properties are valid:
object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
下一个建议是尝试:
resolveLoader: {
fallback: '/usr/local/lib/node_modules'
},
这会产生类似的错误。
是否有人对如何开始使用此配置有任何建议。事实证明,理解文档很困难 - 每两个字都是行话,我找不到引用点来基本了解要开始使用此设置需要做什么。
Webpack.config.js 是:
module.exports = {
entry: './app/app.jsx',
output: {
path: __dirname,
filename: './public/bundle.js'
},
resolve: {
modules: [__dirname, 'node_modules'],
alias: {
Greeter: 'app/components/Greeter.jsx',
GreeterMessage: 'app/components/GreeterMessage.jsx',
GreeterForm: 'app/components/GreeterForm.jsx',
},
extensions: ['.js', '.jsx']
},
// resolveLoader: {
// fallback: '/usr/local/lib/node_modules'
// },
module :{
rules:[{
// use : 'babel-loader',
loader: 'babel-loader',
query :{
presets:['react','es2015']
// ,'es2017'
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
}
]
}
};
最佳答案
我遇到了同样的问题;我通过安装 babel-loader 模块来修复它:
yarn add -D babel-loader
或
npm install --save babel-loader
关于node.js - 无法解析 'babel-loader',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44490481/