Angular 使用相对于@src的角度路径
对于Angular 7应用程序,我有以下几点:Angular 使用相对于@src的角度路径,angular,typescript,angular7,Angular,Typescript,Angular7,对于Angular 7应用程序,我有以下几点: import { environment } from '@src/environments/environment'; tsconfig.json { "compileOnSave": false, "compilerOptions": { "baseUrl": ".", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false
import { environment } from '@src/environments/environment';
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"lib": [
"es2018",
"dom"
],
"typeRoots": [
"node_modules/@types"
],
"paths": {
"core-js/es7/reflect": ["../../node_modules/core-js/proposals/reflect-metadata"],
"core-js/es6/*": ["../../node_modules/core-js/es/*"],
"@src/*": ["src/*"]
}
}
}
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "./app",
"outDir": "../out-tsc/app"
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
tsconfig.app.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"lib": [
"es2018",
"dom"
],
"typeRoots": [
"node_modules/@types"
],
"paths": {
"core-js/es7/reflect": ["../../node_modules/core-js/proposals/reflect-metadata"],
"core-js/es6/*": ["../../node_modules/core-js/es/*"],
"@src/*": ["src/*"]
}
}
}
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "./app",
"outDir": "../out-tsc/app"
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
在一个组件上,我有以下内容:
import { environment } from '@src/environments/environment';
但是,当我构建应用程序时,会出现以下错误:
Cannot find module '@src/environments/environment'.
我缺少什么?在您的tsconfig.json添加中
"baseUrl": "./",
然后删除tsconfig.app.json中的baseUrl
然后确保重新启动angular cli,然后再次运行