Xiu*_*rik 6 typescript visual-studio-code angular
因此,我将 Angular 8.2(项目模板)中的项目更新到版本 10,并按照https://update.angular.io/ 中的说明进行操作,一切正常,但是当实施路径映射时,痛苦开始了,我到处都有这个错误:
Cannot find module '@environments/environment' or its corresponding type declarations.ts(2307)
Run Code Online (Sandbox Code Playgroud)
这个错误适用于在路径中声明的@environments和@modules,其他的没有显示任何错误,因为它们没有被使用。
现在项目在使用ng build时正确构建,还没有尝试ng build --prod,没有出现错误,但Visual Studio Code (v1.46.1)向我显示了有错误的导入,这是我有:
源代码/tsconfig.json
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./e2e/tsconfig.json"
}
]
}
Run Code Online (Sandbox Code Playgroud)
src/tsconfig.app.json
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./lw/app",
"types": []
},
"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["src/**/*.d.ts"],
"exclude": ["src/test.ts", "src/**/*.spec.ts"]
}
Run Code Online (Sandbox Code Playgroud)
src/tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "src",
"outDir": "./dist/lw",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "es2020",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"emitDecoratorMetadata": true,
"noImplicitAny": false,
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"paths": {
"@angular/*": ["./node_modules/@angular/*"],
"@assets/*": ["assets/*"],
"@environments/*": ["environments/*"],
"@api/*": ["app/api/*"],
"@components/*": ["app/components/*"],
"@login/*": ["app/login/*"],
"@models/*": ["app/models/*"],
"@pages/*": ["app/pages/*"],
"@services/*": ["app/services/*"],
"@shared/*": ["app/shared/*"]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictTemplates": true,
"strictInjectionParameters": true
}
}
Run Code Online (Sandbox Code Playgroud)
注意:尝试过 "baseUrl": "src" 和 "baseUrl": "./src" 和 "baseUrl": "./" 并且没有任何变化。
构建结果
Cannot find module '@environments/environment' or its corresponding type declarations.ts(2307)
Run Code Online (Sandbox Code Playgroud)
VSCode 信息
Version: 1.46.1 (user setup)
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:13:20.174Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.18363
Run Code Online (Sandbox Code Playgroud)
角 CLI
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ ? \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.0.1
Node: 12.18.1
OS: win32 x64
Angular: 10.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.1
@angular-devkit/build-angular 0.1000.1
@angular-devkit/build-optimizer 0.1000.1
@angular-devkit/build-webpack 0.1000.1
@angular-devkit/core 10.0.1
@angular-devkit/schematics 10.0.1
@angular/cli 10.0.1
@ngtools/webpack 10.0.1
@schematics/angular 10.0.1
@schematics/update 0.1000.1
rxjs 6.5.5
typescript 3.9.6
webpack 4.43.0
Run Code Online (Sandbox Code Playgroud)
这里还有一张我的项目是如何组织的图片
还有一件非常奇怪的事情是,例如我有 2 个服务(我在每个服务中都有问题)一个CityService(正在使用)和ColorService(未使用),CityService没有显示任何错误并且我可以访问模块定义 (F12),但在具有相同结构的ColorService 中,问题出现并显示为红色。
| 归档时间: |
|
| 查看次数: |
1901 次 |
| 最近记录: |