我有一个奇怪的问题。结构如下:
- 应用程序目录外我自己的库
- 主应用程序,其中库通过tsconfig.json包含,路径也包含在内。
当我使用“ng serve”时,一切都很好,进行生产构建时,构建失败,主要有两个错误:
Error: ../../../../xy/advweb/dist/advweb/core/lib/validators/lessThanDate.validator.d.ts:2:26 - error TS7016: Could not find a declaration file for module 'luxon'. 'C:/_Projects/_Git/yy/Source/src/web/node_modules/luxon/build/node/luxon.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/luxon` if it exists or add a new declaration (.d.ts) file containing `declare module 'luxon';`
2 import { DateTime } from 'luxon';
~~~~~~~
Error: ../../../../xy/advweb/dist/advweb/leaflet/lib/components/map/map.component.d.ts:2:39 - error TS7016: Could not find a declaration file for module 'leaflet'. 'C:/_Projects/_Git/yy/Source/src/web/node_modules/leaflet/dist/leaflet-src.js' implicitly has an 'any' type.
If the 'leaflet' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/leaflet'
2 import { TileLayerOptions, Map } from 'leaflet';
类型安装在应用中。当“node_modules”出现在库项目中时,构建工作。因此,构建似乎在库结构中查找@类型,而不是在应用中。通过tsconfig.json重定向@类型没有帮助。为什么?tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"traceResolution": true,
"baseUrl": "./",
"outDir": "./dist",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"useDefineForClassFields": false,
"module": "ES2022",
"target": "ES2022",
"lib": [
"ES2022",
"DOM"
],
"paths": {
"@angular/*": [
"./node_modules/@angular/*"
],
"luxon": [
"./node_modules/luxon"
],
"*": [
"./node_modules/*"
],
"@advweb/core": [
"../../../../xy/advweb/dist/advweb/core"
],
"@advweb/kendo2": [
"../../../../xy/advweb/dist/advweb/kendo2"
],
"@advweb/leaflet": [
"../../../../xy/advweb/dist/advweb/leaflet"
]
}
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
tsconfig.app.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts"
],
"include": [
"src/**/*.d.ts"
]
}
我做了一个较小的样例项目,结构相同,构建工作正常。我在应用程序和样例中使用了大致相同的angular.json和tsconfig.json。但结果不同。
1条答案
按热度按时间r6vfmomb1#
types
用于指定要包括但不在源文件中引用的类型包名称。当您将数组留空时,这将排除类型。
如果您从
tsconfig.app.json
中删除types
定义,它应该允许typeRoots
中的所有类型,如果我没有记错的话,默认为node_modules/@types