【问题标题】:Angular: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schemaAngular:无效的配置对象。 Webpack 已使用与 API 模式不匹配的配置对象进行初始化
【发布时间】:2020-12-01 22:53:06
【问题描述】:

我的项目工作正常,直到我将整个项目文件夹复制到另一台机器上,这就是我现在在新机器上得到的:

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

任何想法可能导致这种情况?

【问题讨论】:

    标签: javascript node.js angular webpack single-page-application


    【解决方案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"
    
    ],
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 是的,我删除了它。它仍然无法正常工作。即使有两个 \bs-datepicker.css 引用,它也可以在以前的机器上工作
      • 前一台机器上运行良好的代码也随机决定在一段时间后停止工作。事实证明这确实是因为样式中的重复条目。我之前尝试过删除重复的条目,但它不起作用,但那是因为删除了错误的重复条目。 "node_modules/bootstrap/dist/css/bootstrap.min.css","./node_modules/bootstrap/dist/css/bootstrap.min.css", 应该是 "node_modules/bootstrap/dist/css/bootstrap.min.css"
      • 很高兴为您提供帮助。干杯
      • 我面临同样的问题:.../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css' 两次。但是我查看 node_modules 文件可以看到只有 1 个 bs-datepicker.css 条目我该如何解决这个错误?
      【解决方案3】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2018-08-16
        • 2019-08-29
        • 2020-01-23
        • 2017-06-22
        • 2019-10-12
        • 1970-01-01
        • 1970-01-01
        • 2018-12-19
        相关资源
        最近更新 更多