配置对象无效。 Webpack已使用配置进行初始化

时间:2016-09-20 18:08:54

标签: angular angular2-cli

截至今天上午,使用Angular CLI 1.0.0-beta.14ng new try3ng serve并收到以下错误:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'tslint'. These properties are valid:
   object { amd?, bail?, cache?, context?, devServer?, devtool?, entry, externals?, loader?, module?, name?, dependencies?, node?, output?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
 - configuration.module has an unknown property 'preLoaders'. These properties are valid:
   object { rules?, loaders?, noParse?, unknownContextRequest?, unknownContextRegExp?, unknownContextRecursive?, unknownContextCritical?, exprContextRequest?, exprContextRegExp?, exprContextRecursive?, exprContextCritical?, wrappedContextRegExp?, wrappedContextRecursive?, wrappedContextCritical? }
   Options affecting the normal modules (`NormalModuleFactory`).
 - configuration.node.global should be a boolean.
 - configuration.resolve has an unknown property 'root'. These properties are valid:
   object { modules?, descriptionFiles?, plugins?, mainFields?, aliasFields?, mainFiles?, extensions?, enforceExtension?, moduleExtensions?, enforceModuleExtension?, alias?, symlinks?, unsafeCache?, cachePredicate?, fileSystem?, resolver? }
 - configuration.resolve.extensions[0] should not be empty.
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'tslint'. These properties are valid:
   object { amd?, bail?, cache?, context?, devServer?, devtool?, entry, externals?, loader?, module?, name?, dependencies?, node?, output?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
 - configuration.module has an unknown property 'preLoaders'. These properties are valid:
   object { rules?, loaders?, noParse?, unknownContextRequest?, unknownContextRegExp?, unknownContextRecursive?, unknownContextCritical?, exprContextRequest?, exprContextRegExp?, exprContextRecursive?, exprContextCritical?, wrappedContextRegExp?, wrappedContextRecursive?, wrappedContextCritical? }
   Options affecting the normal modules (`NormalModuleFactory`).
 - configuration.node.global should be a boolean.
 - configuration.resolve has an unknown property 'root'. These properties are valid:
   object { modules?, descriptionFiles?, plugins?, mainFields?, aliasFields?, mainFiles?, extensions?, enforceExtension?, moduleExtensions?, enforceModuleExtension?, alias?, symlinks?, unsafeCache?, cachePredicate?, fileSystem?, resolver? }
 - configuration.resolve.extensions[0] should not be empty.
    at webpack (/home/jan/src/fm-repos/try3/node_modules/webpack/lib/webpack.js:16:9)
    at Class.run (/home/jan/src/fm-repos/try3/node_modules/angular-cli/tasks/serve-webpack.js:23:27)
    at /home/jan/src/fm-repos/try3/node_modules/angular-cli/commands/serve.js:84:26
    at process._tickCallback (internal/process/next_tick.js:103:7)

上一次我ng new项目是几天前 - 那时它起作用了。这是我的环境:

angular-cli: 1.0.0-beta.14
node: 6.5.0
os: linux x64

7 个答案:

答案 0 :(得分:31)

将Angular CLI升级到1.0.0-beta.15或更高版本:

  npm uninstall angular-cli -g
  npm cache clean
  npm install angular-cli@latest -g

生成工作支架:

  ng new try4
  cd try4
  ng serve

如果您使用Angular CLI的早期版本构建现有项目,则需要升级:

  rm -rf node_modules dist tmp
  npm install angular-cli@latest --save-dev
  ng init

并仔细检查每个文件中的每个差异。

根本原因:一旦Angular CLI版本正常运行,它当然应该停止工作。不幸的是,angular-cli 1.0.0-beta.14 webpack: ^2.1.0-beta.22上有一个“插入符号”依赖 - 请注意^。昨天,webpack发布了与2.1.0-beta.23不兼容的angular-cli 1.0.0-beta.14,因此,由于插入符号^},已部署的angular-cli 1.0.0-beta.14版本已停止运行。为解决此问题,昨天发布了angular-cli 1.0.0-beta.15 已修复 webpack: 2.1.0-beta.22依赖关系 - 请注意缺少^ - 从而避免破坏升级到webpack。有关详细信息,请参阅https://github.com/angular/angular-cli/issues/2234

项目解决方案:如果您不能或不会升级Angular CLI,您可以通过添加< caret webpack依赖来解决< em>将webpack依赖修复到您自己的项目中。当然,你必须保持这种依赖性:

  npm install webpack@2.1.0-beta.22 --save-dev

如果无法升级Angular CLI,请选择此解决方法。

答案 1 :(得分:18)

我今天遇到了运行ng2.0.0项目的问题 解决方案是降级webpack。

npm uninstall webpack --save-dev

npm install webpack@2.1.0-beta.22 --save-dev

这可能会很快修复angular-cli 1.0.0-beta.15生成的package.json。

此修复程序应解决任何现有项目的问题。

答案 2 :(得分:2)

您使用的是webpack2测试版吗?

如果是,您现在无法在配置中使用自定义属性。

您需要通过插件添加自定义属性:

plugins: {
    new webpack.LoaderOptionsPlugin({
      options: {
        postcss: ...
      }
    })
}

答案 3 :(得分:1)

npm卸载webpack --save-dev

接着是

npm install webpack@2.1.0-beta.22 --save-dev

然后你应该能够再次吞咽。解决了我的问题。

答案 4 :(得分:0)

还要确保您的loaders对象位于module

  module: {
    loaders: [{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}]
  }

这解决了我的问题

答案 5 :(得分:0)

您可以尝试运行以下命令:

npm uninstall angular-cli -g
npm cache clean
npm install webpack // Move webpack to latest

答案 6 :(得分:-1)

请检查项目中是否安装了ts-loader。加载.ts文件是必须的。