angular-cli: Using paths inside tsconfig causing error on JIT: field 'browser' doesn't contain a valid alias configuration
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
While using the paths
object inside tsconfig.json
, module resolution doesn’t seem to work anymore since the latest release. It did work on 1.3.0-rc.5
. Ahead of Time does work. This seems to happen when you reference the src
folder or anything lower down the tree
Versions.
@angular/cli: 1.3.0 node: 8.2.1 os: win32 x64 @angular/animations: 4.3.3 @angular/common: 4.3.3 @angular/compiler: 4.3.3 @angular/core: 4.3.3 @angular/forms: 4.3.3 @angular/http: 4.3.3 @angular/platform-browser: 4.3.3 @angular/platform-browser-dynamic: 4.3.3 @angular/router: 4.3.3 @angular/cli: 1.3.0 @angular/compiler-cli: 4.3.3 @angular/language-service: 4.3.3
Repro steps.
- Upgrade cli to version
1.3.0
, this used to work in1.3.0-rc.5
and before - Create a project
- Set a paths property to
"@root/*": ["./*"]
insidetsconfig.app..json
- Change the import of
AppComponent
insideAppModule
toimport { AppComponent } from '@root/app/app.component';
- Run
ng serve
- Run
ng serve --aot
to see that this does work
The log given by the failure.
ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve '@root/app/app.component' in 'C:\Projects\angular-cli-v130-bug\src\app'
resolve '@root/app/app.component' in 'C:\Projects\angular-cli-v130-bug\src\app'
Parsed request is a module
using description file: C:\Projects\angular-cli-v130-bug\package.json (relative path: ./src/app)
Field 'browser' doesn't contain a valid alias configuration
after using description file: C:\Projects\angular-cli-v130-bug\package.json (relative path: ./src/app)
resolve as module
C:\Projects\angular-cli-v130-bug\src\app\node_modules doesn't exist or is not a directory
C:\Projects\angular-cli-v130-bug\src\node_modules doesn't exist or is not a directory
C:\Projects\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
looking for modules in C:\Projects\angular-cli-v130-bug\node_modules
using description file: C:\Projects\angular-cli-v130-bug\package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: C:\Projects\angular-cli-v130-bug\package.json (relative path: ./node_modules)
using description file: C:\Projects\angular-cli-v130-bug\package.json (relative path: ./node_modules/@root/app/app.component)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\Projects\angular-cli-v130-bug\node_modules\@root\app\app.component doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\Projects\angular-cli-v130-bug\node_modules\@root\app\app.component.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\Projects\angular-cli-v130-bug\node_modules\@root\app\app.component.js doesn't exist
as directory
C:\Projects\angular-cli-v130-bug\node_modules\@root\app\app.component doesn't exist
Desired functionality.
I would like to see no errors, obviously 😉
Mention any other details that might be useful.
Created a repo showing this issue
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 16
- Comments: 43 (3 by maintainers)
Commits related to this issue
- fix(@ngtools/webpack): fix paths mapping recursive support Some path mappings (see issue) were not resolving properly when they were used in deep paths. Fixes #7341 — committed to hansl/angular-cli by hansl 7 years ago
- fix(@ngtools/webpack): fix paths mapping recursive support Some path mappings (see issue) were not resolving properly when they were used in deep paths. Fixes #7341 — committed to angular/angular-cli by hansl 7 years ago
- fix(@ngtools/webpack): fix paths mapping recursive support Some path mappings (see issue) were not resolving properly when they were used in deep paths. Fixes #7341 — committed to angular/angular-cli by hansl 7 years ago
- fix(@ngtools/webpack): fix paths mapping recursive support Some path mappings (see issue) were not resolving properly when they were used in deep paths. Fixes #7341 — committed to angular/angular-cli by hansl 7 years ago
- fix(@ngtools/webpack): fix paths mapping recursive support Some path mappings (see issue) were not resolving properly when they were used in deep paths. Fixes #7341 — committed to d2clouds/speedray-cli by hansl 7 years ago
Is this something that can be fixed quickly? It’s a show-stopper for us.
After fighting some days to put an “emulated” type monorepo, i got working and compiling in AOT mode with paths mappings in the current version (1.4.1) of the CLI.
So my approach have some config time. First, i’m using multi app support and let’s start on angular-cli.json. For the test project, called playground and you can see on the screenshot bellow i’ve use two configs for the same project, this only to have different tsconfig.app.json for resolving ts path maps.
I’ve a shared code on lib, and want to share between the multiple apps. On tsconfig.json in the root my config is like this:
tsconfig.json
Then inside the playground project i have two tsconfig for dev mode and for aot compilation.
tsconfig.dev.json (DEV)
tsconfig.play.json (AOT)
And for this to work package.json scripts have to done some things before compile it, special on AOT mode. For this i copy folder lib to inside the playground app and that’s the action that is needed for resolve paths in path mapping.
package.json
As you can see on
start:play
i call playground-dev to have dev mode and onbuild:play:aot
the playground for AOT.With this configs, i have multi apps like website, b2b app, mobile and so on emulating monorepo, sharing code, components and styles on my company.
An extensive temporary fix to use path maps of ts. Main value copy my shared lib to the project that i’m compiling.
The only problem that i’m facing is on run test, but i think it’s a different thing from this thread. Current error on karma:
Help on this.
Cheers.!!
I found the answer, it turns out that flatModuleId needs to be set to @scope such as
Thanks to @jdjuan #75
@miguelramos Hey, I noticed you have followed a similar path with me. I have an open source repo https://github.com/nekkon/angular-cli-library which follows a similar logic with yours.
Same here - 1.4.0
EDIT
Even after updating the
yarn.lock
file, error is still thereError still persists with
1.3.2
in dherges/ng-packaged@e4f5b3aBuild error started when upgrading from
1.3.0-rc.3
to1.3.0
in dherges/ng-packaged@3c983aeHistory of commits w/ build success anf ailures
Updating to
1.4.0-rc.0
does not solve the error in dherges/ng-packaged#29Error message
Configuration
tsconfig.app.json
.angular-cli.json
I have the same problem as @PierreDuc described. I have tried v1.3.1 and 1.4.0-beta.2, both resulted the same error message. Can anyone from the team respond to this issue ?
Thanks.
@bastienJS check if you have an import from
@angular/src/.../...
, this can also cause this error. Make sure to import only from@angular/core
etc. Nothing fromsrc
. Thereby the issue I mentioned is only present in JIT and -not- in AOTI get the same error: Field ‘browser’ doesn’t contain a valid alias configuration
with v1.3.0 but I do not use AOT or paths in tsconfig.json!
@PierreDuc et al: Fix the
@angular/cli
version in package.json to1.3.0-rc.5
resolves the issue for me. This only occurs in^1.3.0
. @filipesilva FYI. Maybe the reason is what @karptonite has said.