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.5and before - Create a project
- Set a paths property to
"@root/*": ["./*"]insidetsconfig.app..json - Change the import of
AppComponentinsideAppModuletoimport { AppComponent } from '@root/app/app.component'; - Run
ng serve - Run
ng serve --aotto 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
I had this issue which was caused by the following in tsconfig.json:
"paths": {
"@angular/*": [
"./node_modules/@angular/*"
]
}
Not sure why it was added or what changed that caused this to break everything, our project had been building fine up until 22/02/18 with this in that file. I've removed it and now it's working.
Similar to @miguelramos, in my case in tsconfig I had compilerOptions -> "target": "es2015", but compilerOptions -> lib: ["dom", "es2018"] This is for a project to be used as a library by other projects. I kept getting all kinds of "Field ‘browser’ doesn’t contain a valid alias configuration" and module/blabla not found errors when trying production build (no errors on dev) My very uneducated guess is that is there´s a discrenpancy between "target" and "lib" routes get screwed up. The "host" app is told to look for modules and classes in one place but they are placed / generated elsewhere. If this is the case error reporting is not helping at all. I don´t know if its possible, but you should be warned when compiling. It´s just really hard to figure this out when you´re told files are not found (again only in production build) when the files are there,
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.