question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module resolution fails in v1.7.0 when "baseUrl" is set in tsconfig

See original GitHub issue

Versions

Angular CLI: 1.7.0
Node: 8.9.4
OS: linux x64
Angular: 5.2.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.0
@angular-devkit/build-optimizer: 0.3.1
@angular-devkit/core: 0.3.1
@angular-devkit/schematics: 0.3.1
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.0
@schematics/angular: 0.3.1
@schematics/package-update: 0.3.1
typescript: 2.6.2
webpack: 3.11.0

Repro steps

  • Run git clone https://github.com/mprahl/angular-cli-9671-reproducer.git
  • Run cd angular-cli-9671-reproducer && npm install && ng serve

Observed behavior

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve 'reproducer/hello/hello.component' in '/path/to/angular-cli-9671-reproducer/src/app'

Desired behavior

The imports should work as they did in v1.6.x.

Mention any other details that might be useful (optional)

The following commit broke this functionality: https://github.com/angular/angular-cli/commit/29aa274b6721c1399ca2baca18565b21254fb3f0

Running angular-cli with commit https://github.com/angular/angular-cli/commit/29aa274b6721c1399ca2baca18565b21254fb3f0 reverted works as expected.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Akimicommented, May 8, 2018

Is this issue still present in angular cli 6.0.0? Or there is some new solution? What is the correct way to have imports like import { } from "shared" instead of import { } from "../../../../../shared"?

I tried angular cli 6.0.0 and it seems the problem is still here.

EDIT:

I was mistaken, after upgrade to angular-cli 6.0.0 everything works OK now.

1reaction
FDIMcommented, Mar 15, 2018

I am having the same issue as well, but in my case we have one app (styleguide) that is outside of the src folder and building that app fails with cli 1.7.3, while it works with 1.6.x. Seems like baseUrl option in tsconfig.json is partly respected? And yes, almost all our paths are relative to root directory.

EDIT: I’ve got it to work for js/ts files with this:

...
"baseUrl" : ".",
"paths": {
  "*": [ "node_modules/*", "source/*", "styleguide/*"]
}
...

But now it breaks for html files which we are still requiring in older angularjs files (we are in a process of upgrading).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import ... A non-relative import can be resolved relative to...
Read more >
Typescript module resolution not working - Stack Overflow
When I hover the 'utils/IntHelper' part in my import line in the typescript file VSCode would also show the correct path to that...
Read more >
Typescript does not resolve modules through tsconfig.json's ...
WebStorm does support 'baseURL' and correctly generates/resolves imports using it. ... I have `moduleResolution: node` set as well.
Read more >
Migration Guide | Cypress Documentation
Migrating to Cypress 12.0 This guide details the changes and how to change your code to migrate to Cypress version 12.0.
Read more >
Configuration Languages - webpack
The first option is to open your tsconfig.json file and look for compilerOptions . Set target to "ES5" and module to "CommonJS" ...
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