tsconfig paths and module resolution errors in VS Code

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.9 node: 7.9.0 os: darwin x64 @angular/animations: 4.4.5 @angular/common: 4.4.5 @angular/compiler: 4.4.5 @angular/core: 4.4.5 @angular/forms: 4.4.5 @angular/http: 4.4.5 @angular/platform-browser: 4.4.5 @angular/platform-browser-dynamic: 4.4.5 @angular/router: 4.4.5 @angular/cli: 1.4.9 @angular/compiler-cli: 4.4.5 typescript: 2.3.4

macOS Sierra 10.12.6 VS Code 1.17.2

Repro steps.

My tsconfig path property seems broken. When I replace my path mapped imports (@shared, @assets etc.) with the equivalent coded relative paths, typescript module resolution seems to work (vs code intellisense is happy) I have a large angular 2 project and am used to aliasing my asset and shared directories this way. NOTE: project builds and (seems) to run just fine This has been reported often, but I can’t make sense of the current state of this issue. This more than annoying as VS Code reports Angular spurious errors on all of my components. I also suspect this is why I get the infamous Can’t read property isSkipSelf of null when I open my templates (html) in VS Code. I was running 1.4.2 and just tried ~1.4.2, which resolves to 1.4.9 in my package.json, to no avail. Will 1.5.x fix this? How can I help debug this without providing a copy of my app?

Thanks in advance. Regards.

The log given by the failure.

Desired functionality.

Mention any other details that might be useful.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:41
  • Comments:42 (5 by maintainers)

github_iconTop GitHub Comments

64reactions
sandangelcommented, Jan 13, 2018

@mehs2690 can you type environment in editor ( don’t add import statement yet ) and then press Ctrl + . when cursor in environment to see what option vscode suggest? Remember that because tsconfig.json and tsconfig.json has different baseUrl so you have to align path config accordingly

here is my config: tsconfig.json

"baseUrl": "./",
    "paths": {
      "@app/*": ["src/app/*"],
      "@env/*": ["src/environments/*"],
      "@views/*": ["src/app/views/*"]
    }

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": [],
    "paths": {
      "@app/*": ["app/*"],
      "@env/*": ["environments/*"],
      "@views/*": ["app/views/*"]
    }
  },
  "exclude": ["test.ts", "**/*.spec.ts"],
  "angularCompilerOptions": {
    "annotationsAs": "static fields",
    "annotateForClosureCompiler": true,
    "preserveWhitespaces": false,
    "fullTemplateTypeCheck": true
  }
}

50reactions
johankvintcommented, Mar 21, 2018

I had the same issue but it seams it was resolved with using a more “explicit” relative path in baseUrl in tsconfig.tswith "./src"

Before:

{
    "compilerOptions": {
        "baseUrl": "src",
        "paths": {
            "@app/*": ["app/*"],
        }
    }
}

After:

{
    "compilerOptions": {
        "baseUrl": "./src",
        "paths": {
            "@app/*": ["app/*"],
        }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Code can't resolve angular's tsconfig paths
VsCode automatically looks for a tsconfig.json file and it doesn't care about tsconfig.app.json , so paths needs to be specified in tsconfig.
Read more >
TypeScript Compiling with Visual Studio Code
A simple tsconfig.json looks like this for ES5, CommonJS modules and source maps: ... How do I resolve a TypeScript "Cannot compile external...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import ... import can be resolved relative to baseUrl ,...
Read more >
tsconfig-paths - npm
The typescript compiler can resolve these paths from tsconfig so it will compile OK. But if you then try to execute the compiled...
Read more >
How to handle tsconfig path aliases : r/typescript - Reddit
error, where it can't resolve my path alias of "@something". I was using the Live Preview extension in VSCode before, the paths and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found