npx webpack命令找不到模块webpack.config.js

时间:2019-02-09 08:33:40

标签: javascript webpack

我遵循官方的Webpack入门指南,并且在使用配置部分出现错误。它说要使用以下命令创建webpack.config.js文件:

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist')
  }
};

然后我运行以下命令: npx webpack --config webpack.config.js

我得到的错误是:

Cannot find module '/Users/Documents/Web_Development/tone/webpack.config.js'

该指南似乎并未对此处可能存在的问题给出任何想法。我的代码编辑器还告诉我const path = require('path');出现错误,说“期望JSON对象,数组或文字;

我的目录结构:

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

1 个答案:

答案 0 :(得分:0)

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