Module resolution fails in v1.7.0 when "baseUrl" is set in tsconfig
See original GitHub issueVersions
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:
- Created 6 years ago
- Reactions:3
- Comments:14 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 ofimport { } 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.
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:
But now it breaks for html files which we are still requiring in older angularjs files (we are in a process of upgrading).