angular-cli: Scoped library paths cannot be resolved
See also https://github.com/angular/angular-cli/issues/10172 The generated path aliases seem not right.
Versions
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 6.0.0
Node: 10.0.0
OS: linux x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-ng-packagr 0.6.0
@angular-devkit/build-optimizer 0.6.0
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0
@schematics/update 0.6.0
ng-packagr 3.0.0-rc.2
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
Repro steps
ng new my-project
cd my-project
ng generate library foo
ng generate library @msterba/bar
ng build foo
ng build @msterba/bar
Now try to import BarModule
into the app.
Observed behavior
The libraries are compiled correctly but the resulting directory structure in dist
is not reflected by the paths
definitions in tsconfig.json
:
directory structure:
dist
+- foo
+- @msterba
+- bar
tsconfig.json:
"paths": {
"foo": [
"dist/foo"
],
"bar": [
"dist/bar"
]
}
BarModule
cannot be imported.
// src/app/app.module.ts:
import { FooModule } from 'foo'; // ok
import { BarModule } from '@msterba/bar'; // [ts] Cannot find module '@msterba/bar'.
// console:
$ ng build
ERROR in src/app/app.module.ts(8,27): error TS2307: Cannot find module '@msterba/bar'.
Desired behavior
Add scopes to the paths
definitions.
"paths": {
"foo": [
"dist/foo"
],
"@msterba/bar": [
"dist/@msterba/bar"
]
}
Mention any other details that might be useful (optional)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 17
- Comments: 15 (6 by maintainers)
I’m on version 6.2.2 (which I believe is well after the fix was merged in) and am seeing exactly the same issue as @maxime1992
Not sure that issue’s resolved 🤷♂️
I’ve been upgrading to the following:
and I get the error:
/tsconfig.json
:I can see that the dist folder contains
visualiser-sandbox
and everything into it:Temporary fix: use npm link In my case:
I’m not sure what’s going wrong here but you really shouldn’t use
npm link
. There are many, many situations where things will break because of it.So I’m not sure whether it’s the same thing or not but I moved away from using libraries within the dist folder and instead pick up from the source directly.
became
When navigation with the IDE inside the code it’s also giving me better access to the source instead of pointing to the dist folder 👍
a similar issue: https://github.com/angular/angular-cli/issues/10444 the suggestion, adding a path definition to tsconfig.lib.json, from @aboodz works for me:
Same to load feature module with lazy loading
ERROR in Could not resolve module app/user/user.module relative to /C/dsv/client/pwa-ng/src/app/app.routing.ts