"无效的配置对象"使用" npm init"创建package.json之后

时间:2017-03-15 09:55:11

标签: json node.js webpack

我有一个正在运行的webpack配置。但是在使用npm init创建以下package.json文件之后:

{


 "name": "y",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.24.0",
    "babel-loader": "^6.4.0",
    "babel-preset-es2015": "^6.24.0",
    "babel-preset-react": "^6.23.0",
    "jshint": "^2.9.4",
    "jshint-loader": "^0.8.4",
    "node-libs-browser": "^2.0.0",
    "webpack": "^2.2.1"
  }
}

并安装以下模块:

npm install babel-core babel-loader jshint jshint-loader node-libs-browser  
babel-preset-es2015 babel-preset-react webpack  --save-dev

我收到了错误消息

  

无效的配置对象。 Webpack已使用配置进行初始化    与API架构不匹配的对象。     - configuration.resolve.extensions [0]不应为空。

当我尝试使用

重启dev服务器时

webpack-dev-server

webpack.config.json如下所示:

module.exports = {
  entry: ["./global.js", "./app.js"],
  output: {
    filename: "bundle.js"
  },
  module: {
   loaders: [
     {
       test: /\.es6$/,
       exclude: /node_modules/,
       loader: 'babel-loader',
       query: {
         presets: ['react', 'es2015']
       }
     }
   ]
 },
 resolve: {
   extensions: ['', '.js', '.es6']
 },
}

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您安装了最新版本的webpack:

npm install --save-dev webpack

Webpack 2不再允许resolve.extensions中的空字符串。只需从扩展数组中删除空字符串:

resolve: {
  extensions: ['.js', '.es6']
},

您还应该阅读官方Migration Guide