Reputation: 136
I run into the following error message when tried to set up webpack 2 with babel:
ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in 'path_to_project_dir'
The configuration file following the webpack 2 docs:
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
I have the following dev dependencies in my 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"
},
My node and npm versions are:
node 7.7.1
npm 4.4.1
My OS is macOS Sierra
What could be the source of this error message, and how should I solve it. I tried a lot of tutorials and blog posts to find a solution but none of them worked.
Upvotes: 4
Views: 4936
Reputation: 136
I investigated the node_modules
directory and found a lot of dependencies missing. I deleted the node_modules
directory and yarn.lock
file and from a new Terminal window ran the yarn
command.
It worked, installed all the dependencies, and webpack 2 & babel worked as it should.
As originally I installed the npm modules with atom editor's term3 terminal
,
I tried to do the same reinstall there, however it produced missing dependencies as originally.
So the error has been caused by the term3 package of atom
Solution: use the standard terminal, and DON'T use the terminal provided by the term3 package of atom
Upvotes: 3