角度:无效的配置对象。已使用与API模式不匹配的配置对象初始化了Webpack

时间:2019-05-14 14:05:09

标签: javascript angular webpack angular-cli

我的项目运行良好,直到将整个项目文件夹复制到另一台机器上,这就是我现在在新机器上得到的东西:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]
   -> The entry point(s) of the compilation.
   Details:
    * configuration.entry should be an instance of function
      -> A Function returning an entry object, an entry string, an entry array or a promise to these things.
    * configuration.entry['styles'] should be a string.
      -> The string is resolved to a module which is loaded upon startup.
    * configuration.entry['styles'] should not contain the item 'G:\MyProjects\kud2\node_modules\ngx-bootstrap\datepicker\bs-datepicker.css' twice.
    * configuration.entry should be a string.
      -> An entry point without name. The string is resolved to a module which is loaded upon startup.
    * configuration.entry should be an array:
      [non-empty string]
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]
   -> The entry point(s) of the compilation.
   Details:
    * configuration.entry should be an instance of function
      -> A Function returning an entry object, an entry string, an entry array or a promise to these things.
    * configuration.entry['styles'] should be a string.
      -> The string is resolved to a module which is loaded upon startup.
    * configuration.entry['styles'] should not contain the item 'G:\MyProjects\kud2\node_modules\ngx-bootstrap\datepicker\bs-datepicker.css' twice.
    * configuration.entry should be a string.
      -> An entry point without name. The string is resolved to a module which is loaded upon startup.
    * configuration.entry should be an array:
      [non-empty string]
    at webpack (G:\MyProjects\kud2\node_modules\webpack\lib\webpack.js:31:9)
    at Observable.rxjs_1.Observable.obs [as _subscribe] (G:\MyProjects\kud2\node_modules\@angular-devkit\build-webpack\src\webpack-dev-server\index.js:39:37)
    at Observable._trySubscribe (G:\MyProjects\kud2\node_modules\rxjs\internal\Observable.js:44:25)
    at Observable.subscribe (G:\MyProjects\kud2\node_modules\rxjs\internal\Observable.js:30:22)
    at G:\MyProjects\kud2\node_modules\rxjs\internal\util\subscribeTo.js:22:31
    at Object.subscribeToResult (G:\MyProjects\kud2\node_modules\rxjs\internal\util\subscribeToResult.js:10:45)
    at MergeMapSubscriber._innerSub (G:\MyProjects\kud2\node_modules\rxjs\internal\operators\mergeMap.js:82:29)
    at MergeMapSubscriber._tryNext (G:\MyProjects\kud2\node_modules\rxjs\internal\operators\mergeMap.js:76:14)
    at MergeMapSubscriber._next (G:\MyProjects\kud2\node_modules\rxjs\internal\operators\mergeMap.js:59:18)
    at MergeMapSubscriber.Subscriber.next (G:\MyProjects\kud2\node_modules\rxjs\internal\Subscriber.js:67:18)
    at TapSubscriber._next (G:\MyProjects\kud2\node_modules\rxjs\internal\operators\tap.js:65:26)
    at TapSubscriber.Subscriber.next (G:\MyProjects\kud2\node_modules\rxjs\internal\Subscriber.js:67:18)
    at MergeMapSubscriber.notifyNext (G:\MyProjects\kud2\node_modules\rxjs\internal\operators\mergeMap.js:92:26)
    at InnerSubscriber._next (G:\MyProjects\kud2\node_modules\rxjs\internal\InnerSubscriber.js:28:21)
    at InnerSubscriber.Subscriber.next (G:\MyProjects\kud2\node_modules\rxjs\internal\Subscriber.js:67:18)
    at MergeMapSubscriber.notifyNext (G:\MyProjects\kud2\node_modules\rxjs\internal\operators\mergeMap.js:92:26)

Package.json

{
  "name": "kud2",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "bootstrap": "^3.4.1",
    "core-js": "^2.5.4",
    "ngx-bootstrap": "^4.1.1",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "webpack-cli": "^3.3.2",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.9",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2",
    "webpack": "^4.31.0"
  }
}

我尝试重新安装webpack,但无济于事。

npm uninstall webpack --save-dev
npm install webpack --save-dev

有什么想法会导致这种情况吗?

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,这就是我解决的方法。我在angular.json中使用了两种样式

"styles": [
    "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
    "src/styles.css",
    "node_modules/bootstrap/dist/css/bootstrap.min.css",
    "src/styles.css"

 ],

如您所见,有两个"src/style.css"

新代码

"styles": [
   "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
   "src/styles.css",
   "node_modules/bootstrap/dist/css/bootstrap.min.css"

],

答案 1 :(得分:0)

  

configuration.entry ['styles']不应包含该项   'G:\ MyProjects \ kud2 \ node_modules \ ngx-bootstrap \ datepicker \ bs-datepicker.css'   两次。

我在日志中看到一些重复的样式条目配置,您可以检查一下是否在项目中使用它吗?

答案 2 :(得分:0)

运行命令后,我遇到了同样的问题:

ng添加ngx-bootstrap --component工具提示

这为angular.json添加了额外的“ node_modules / bootstrap / dist / css / bootstrap.min.css”引用,将其删除后已修复错误