不能在另一个项目中使用本地修改的 Angular 模块
Can't use a locally modified Angular module inside another project
我在 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 但我不知道 if/when 维护者是否会接受它,我想在中使用修改后的模块至少在此期间。
当然,我已经通过内部演示应用程序使用它们测试了这些更改(有一些微不足道的临时更改)并且一切正常。然后我用
构建 dist
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
------------------------------------------------------------------------------
几乎尝试了所有方法...最后我正在导入源代码,看起来它想要根目录中的项目文件夹而不是它之外的路径,所以我从下面的模块存储库中复制了项目文件夹我的应用程序的根目录并指向它
import { NgxChartsModule } from '../projects/swimlane/ngx-charts/src/lib/ngx-charts.module';
至少,现在我的 ng serve
运行 很好(所以我对这个 solution/workaround 很满意)
编译器选项
我忘记分享我必须在 tsconfig.json
中更新的设置
"strict": false,
"noImplicitReturns": false,
及以下
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": false,
"strictInputAccessModifiers": false,
"strictTemplates": false
}
无论如何,正如我在下面的评论中所指出的,我(还)没有向用户发布我修改过的模块,但是标准的 percentageFormatting
到小数点后零位(这似乎很公平)
我在 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 但我不知道 if/when 维护者是否会接受它,我想在中使用修改后的模块至少在此期间。
当然,我已经通过内部演示应用程序使用它们测试了这些更改(有一些微不足道的临时更改)并且一切正常。然后我用
构建 distng 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
------------------------------------------------------------------------------
几乎尝试了所有方法...最后我正在导入源代码,看起来它想要根目录中的项目文件夹而不是它之外的路径,所以我从下面的模块存储库中复制了项目文件夹我的应用程序的根目录并指向它
import { NgxChartsModule } from '../projects/swimlane/ngx-charts/src/lib/ngx-charts.module';
至少,现在我的 ng serve
运行 很好(所以我对这个 solution/workaround 很满意)
编译器选项
我忘记分享我必须在 tsconfig.json
"strict": false,
"noImplicitReturns": false,
及以下
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": false,
"strictInputAccessModifiers": false,
"strictTemplates": false
}
无论如何,正如我在下面的评论中所指出的,我(还)没有向用户发布我修改过的模块,但是标准的 percentageFormatting
到小数点后零位(这似乎很公平)