小编Luk*_*xim的帖子

Angular 11 tsconfig 路径别名无法识别

我正在使用 Angular 11 并尝试使用短导入import {smthg} from '@common'而不是import {smthg} from '../../../common'

但我总是在 IDEA 中遇到错误: TS2307: Cannot find module '@common' or its corresponding type declarations.

尝试编译 .ts 文件时在控制台中出现同样的错误 ( ng serve)

有趣的是,当我添加/index到导入时,然后IDEA停止诅咒,但错误并没有在控制台中消失

myAngularProject
?   package.json
?   tsconfig.json
?   tsconfig.app.json
?   angular.json    
?
????src
    ?   main.ts
    ?   index.html
    ?
    ????app
        ?  
        ????common
        ?
        ????features
Run Code Online (Sandbox Code Playgroud)

tsconfig.json:

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@common/*": ["app/common/*"],
      "@features/*": …
Run Code Online (Sandbox Code Playgroud)

aliases typescript tsconfig angular angular11

1
推荐指数
2
解决办法
2576
查看次数

标签 统计

aliases ×1

angular ×1

angular11 ×1

tsconfig ×1

typescript ×1