【发布时间】:2021-07-21 14:43:48
【问题描述】:
ng serve 时出现以下错误(我已经尝试清除缓存,重新安装所有模块并重新启动服务器)
Error: ../../../../angular/ngx-charts-master/ngx-charts-master/dist/swimlane/ngx-charts/lib/ngx-charts.module.d.ts:1:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
This likely means that the dependency which declares NgxChartsModule has not been processed correctly by ngcc.
完整的上下文背景是我已经修改了源代码并发布了pull request,但我不知道维护者是否/何时会接受它,并且我想至少同时使用修改后的模块。
当然,我已经通过内部演示应用程序使用它们测试了这些更改(进行了一些琐碎的临时更改),并且一切正常。然后我用
ng build @swimlane/ngx-charts
它在 dist 文件夹 /dist/swimlane/ngx-charts/ 中产生了输出,如上所示,我尝试从中导入
进一步尝试...
我已将导入重写为
import { NgxChartsModule } from '../../../../../../angular/ngx-charts-master/ngx-charts-master/dist/swimlane/ngx-charts';
我删除了 package.json 中的标准条目并从我的本地文件夹中安装了模块
"@swimlane/ngx-charts": "file:../../../../angular/ngx-charts-master/ngx-charts-master/dist/swimlane/ngx-charts",
然后我按照说明安装了开发依赖项
"d3-array": "^2.9.1",
"d3-brush": "^2.1.0",
"d3-color": "^2.0.0",
"d3-format": "^2.0.0",
"d3-hierarchy": "^2.0.0",
"d3-interpolate": "^2.0.1",
"d3-scale": "^3.2.3",
"d3-selection": "^2.0.0",
"d3-shape": "^2.0.0",
"d3-time-format": "^3.0.0",
"d3-transition": "^2.0.0"
(从模块存储库内部库中的项目 json 复制)但 ng serve 仍然失败
Error: ../../../../angular/ngx-charts-master/ngx-charts-master/dist/swimlane/ngx-charts/lib/area-chart/area-chart.component.d.ts:2:29 - error TS7016: Could not find a declaration file for module 'd3-shape'. 'F:/Appl/angular/ngx-charts-master/ngx-charts-master/dist/swimlane/ngx-charts/node_modules/d3-shape/dist/d3-shape.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/d3-shape` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-shape';`
2 import { CurveLinear } from 'd3-shape';
~~~~~~~~~~
Error: ./src/main.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
注意
我没有提到,但现在我怀疑来自 npm run build:lib --prod 的这些警告与问题有关
√ Compiling TypeScript sources through NGC
√ Bundling to FESM2015
/ Bundling to UMDWARNING: No name was provided for external module 'd3-selection' in output.globals – guessing 'd3Selection'
WARNING: No name was provided for external module 'd3-brush' in output.globals – guessing 'd3Brush'
WARNING: No name was provided for external module 'd3-scale' in output.globals – guessing 'd3Scale'
WARNING: No name was provided for external module 'd3-shape' in output.globals – guessing 'd3Shape'
WARNING: No name was provided for external module 'd3-array' in output.globals – guessing 'd3Array'
WARNING: No name was provided for external module 'd3-interpolate' in output.globals – guessing 'd3Interpolate'
WARNING: No name was provided for external module 'd3-format' in output.globals – guessing 'd3Format'
WARNING: No name was provided for external module 'd3-color' in output.globals – guessing 'd3_color'
WARNING: No name was provided for external module 'd3-hierarchy' in output.globals – guessing 'd3Hierarchy'
WARNING: No name was provided for external module 'd3-time-format' in output.globals – guessing 'd3TimeFormat'
√ Bundling to UMD
√ Minifying UMD bundle
√ Writing package metadata
i Built @swimlane/ngx-charts
------------------------------------------------------------------------------
Built Angular Package
- from: F:\Appl\angular\ngx-charts-master\ngx-charts-master\projects\swimlane\ngx-charts
- to: F:\Appl\angular\ngx-charts-master\ngx-charts-master\dist\swimlane\ngx-charts
------------------------------------------------------------------------------
【问题讨论】:
标签: angular angular-cli angular-module angular-library ngx-charts