尝试使用 babel 设置 webpack 2 时遇到以下错误消息:
ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in 'path_to_project_dir'
webpack 2 文档之后的配置文件:
const path = require('path')
const config = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: [
path.resolve(__dirname, 'node_modules')
],
loader: 'babel-loader',
options: {
presets: ["es2015"]
},
}
]
},
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, 'src')
],
extensions: ['.js', '.json', '.jsx'],
}
}
module.exports = config
我的 packages.json 中有以下开发依赖项:
"devDependencies": {
"babel-core": "^6.24.0",
"babel-loader": "^6.4.0",
"babel-preset-es2015": "^6.24.0",
"path": "^0.12.7",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.1"
},
我的节点和 npm 版本是:
node 7.7.1
npm 4.4.1
我的操作系统是 macOS Sierra
此错误消息的来源可能是什么,我应该如何解决它。我尝试了很多教程和博客文章来找到解决方案,但都没有奏效。