简体   繁体   中英

npx webpack command cannot find module webpack.config.js

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"
  }
}

解决方案是将webpack.config.json文件更改为webpack.config.js

You have to make sure that the webpack.config.js file is in the root of your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM