28

截至今天早上,使用 Angular CLI1.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
4

7 回答 7

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.14so不兼容的版本,由于插入符号(^),已部署的版本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,您可以通过将固定的 webpack 依赖项添加到您自己的项目来解决插入符号 webpack 依赖项。当然,您必须保持这种依赖关系:

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

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

于 2016-09-20T18:24:35.920 回答
19

我今天在运行一个 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 上得到修复。

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

于 2016-09-21T05:24:03.700 回答
2

你在使用 webpack2 测试版吗?

如果是,您现在不能在配置中拥有自定义属性。

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

plugins: {
    new webpack.LoaderOptionsPlugin({
      options: {
        postcss: ...
      }
    })
}
于 2016-09-20T19:44:19.763 回答
1

npm 卸载 webpack --save-dev

其次是

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

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

于 2017-02-05T07:23:28.193 回答
0

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

npm uninstall angular-cli -g
npm cache clean
npm install webpack // Move webpack to latest
于 2019-10-10T11:57:22.703 回答
0

还要确保您的loaders对象在module例如

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

这为我解决了这个问题

于 2017-02-22T15:44:02.123 回答
-1

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

于 2017-01-11T16:25:10.263 回答