I’m following the official Webpack getting started guide and I get an error on the Using a Configuration section. It says to create a webpack.config.js file with:
JavaScript
x
10
10
1
const path = require('path');
2
3
module.exports = {
4
entry: './src/index.js',
5
output: {
6
filename: 'main.js',
7
path: path.resolve(__dirname, 'dist')
8
}
9
};
10
I then run the following command:
npx webpack --config webpack.config.js
The error I get is:
Cannot find module '/Users/Documents/Web_Development/tone/webpack.config.js'
The guide does not seem to give any ideas of what could be wrong here. Also my code editor is telling me there is an error with const path = require('path');
saying “Expected a JSON Object, array or literal;
My Directory structure:
JavaScript
1
10
10
1
webpack.config.json
2
package.json.lock
3
package.json
4
node_modules/
5
dist/
6
index.html
7
main.js
8
src/
9
index.js
10
package.json:
JavaScript
1
21
21
1
{
2
"name": "tone",
3
"version": "1.0.0",
4
"description": "",
5
"private": true,
6
"scripts": {
7
"test": "echo "Error: no test specified" && exit 1"
8
},
9
"keywords": [],
10
"author": "",
11
"license": "ISC",
12
"devDependencies": {
13
"babel-core": "^6.26.3",
14
"webpack": "^4.29.3",
15
"webpack-cli": "^3.2.3"
16
},
17
"dependencies": {
18
"lodash": "^4.17.11"
19
}
20
}
21
Advertisement
Answer
The solution was to change the webpack.config.json
file to webpack.config.js
.