2016-09-20 174 views
28

截至今天上午初始化,具有角CLI 1.0.0-beta.14ng new try3ng serve,並得到以下錯誤:無效的配置對象。的WebPack已經使用配置

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 

回答

31

升級角CLI來1.0.0-beta.15或更好:

npm uninstall angular-cli -g 
    npm cache clean 
    npm install [email protected] -g 

產生工作支架:

ng new try4 
    cd try4 
    ng serve 

如果你有一個折角以前的版本構建的現有項目CLI,您需要升級:

rm -rf node_modules dist tmp 
    npm install [email protected] --save-dev 
    ng init 

並仔細檢查每個文件中的每個差異。

根源:一旦角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

項目變通:如果你不能或不會,升級角CLI,您可以通過添加固定的WebPack依賴到自己的項目工作圍繞插入符的WebPack依賴。你必須保持這種依賴關係向前發展,當然是:

npm install [email protected] --save-dev 

選擇此變通如果您不能升級角CLI。

+0

無論出於何種原因,它不停地安裝'1.0.0-beta.14'對我和我有做'npm install -g angular/angular-cli'(直接從GitHub repo安裝)以獲得'1.0.0-beta.15'。 –

+0

我遵循這個,在我的項目上安裝版本beta.15,rm node_modules等''init'得到:無法找到模塊'@ angular/core' –

+0

@AderbalNunes - 請參閱:http://stackoverflow.com/問題/ 39780833/error-can-find-module-angular-core –

2

您使用的是webpack2測試版嗎?

如果是,您現在不能在配置中具有自定義屬性。

你需要通過插件來添加自定義屬性:

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

'angular-cli 1.0.0-beta.15'對'webpack:2.1.0-beta.22'有依賴性(而'angular-cli 1.0 .0-beta.14'依賴於'webpack:^ 2.1.0-beta.22')。 –

+0

@JanNielsen謝謝 – Taspina

+0

不客氣,@Taspina - 我已經更新了我的答案,詳細介紹了爲什麼**它打破了...... –

18

我只是碰到了這個問題,今天運行的ng2.0.0項目 的解決方案是降級的WebPack。

npm uninstall webpack --save-dev 

npm install [email protected] --save-dev 

這將可能很快被固定在那的package.json產生angular-cli 1.0.0-beta.15

此修復程序應解決任何現有項目的問題。

+0

昨天發佈了Angular CLI'1.0.0-beta.15'來解決這個問題,正如我在我的回答中指出的那樣。 –

+2

偉大的傢伙,謝謝你很多。 – albaiti

-1

請檢查ts-loader是否安裝在您的項目中。這是必須和應該加載.ts文件。

1

NPM卸載的WebPack --save-dev的

其次

NPM安裝[email protected] --save-dev的

那麼你應該能夠再次一飲而盡。解決了我的問題。

0

另外,還要確保你的loaders對象正在module

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

這解決了這個問題對我來說