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:
const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'main.js', path: path.resolve(__dirname, 'dist') } };
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:
webpack.config.json package.json.lock package.json node_modules/ dist/ index.html main.js src/ index.js
package.json:
{ "name": "tone", "version": "1.0.0", "description": "", "private": true, "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "babel-core": "^6.26.3", "webpack": "^4.29.3", "webpack-cli": "^3.2.3" }, "dependencies": { "lodash": "^4.17.11" } }
Advertisement
Answer
The solution was to change the webpack.config.json
file to webpack.config.js
.