【发布时间】:2017-11-13 09:37:41
【问题描述】:
我正在尝试配置我的第一个节点反应应用程序。
我不断收到“无法解析 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模块了吗? -
请告诉我们
your webpack.config.js -
@chenkehxx - 是的,babel-loader 在我的开发依赖项中
-
检查你的 webpack 是什么版本,
1.x或2.x -
webpack 是 v2.6.1
标签: node.js webpack babeljs node-modules webpack-2