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
My guess is that this is related to this commit: https://github.com/angular/angular-cli/commit/cb0cc0886506d8243c0ed8fcba6a948ddb5adb25 It was a last minute addition, and seems to have made it into 1.3, despite a commit message that says "This is a feature because we do not want it in 1.3.0".
I'm getting the same errors in my application. I followed the recreate steps and and I get the error without the aot flag so that confirms for me that it is not my app setup but something that changed in 1.3
@PierreDuc et al: Fix the @angular/cli version in package.json to 1.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.
My project does not build anymore after upgrading to 1.3.0 with this same error:
https://travis-ci.org/ngx-plus/ngx-forms/builds/263376710#L3634 https://github.com/ngx-plus/ngx-forms/commit/e7eefe0054ff7509c72ef99d0b0d6314230f8b1e
Is this something that can be fixed quickly? It's a show-stopper for us.
@tacman for me downgrading the local cli version is the workaround
@hansl just bringing this to your attention, since you are the author of the commit that may be related to this issue. See: https://github.com/angular/angular-cli/issues/7341#issuecomment-321636356
I 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!
@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 from src. Thereby the issue I mentioned is only present in JIT and -not- in AOT
For me 1.3.0-rc.5 doesn't work. I downgraded to 1.2.1 and i can build finally.
I get the same error,
and I checked my code, nothing import from @anguar/src/* only import from @angular/core and @angular/core/testing
1.3.0-rc.5 works fine
I can no longer confirm this bug. What I thought was related to the paths config was actually related to having some import statements that explicitly included .ts in the path name. When I removed the .ts at the end of the import path name, the imports worked fine, as before.
If you are seeing the bug described in this issue, check to see whether you are including the .ts extension in your import statements. If you are, try removing it.
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.
The same error (project https://github.com/ngrx/platform.git works with another version cli) @angular/cli: 1.3.1 node: 6.11.2 os: win32 x64 @angular/cdk: 2.0.0-beta.8 @angular/animations: 4.3.5 @angular/cli: 1.3.1 @angular/common: 4.3.5 @angular/compiler: 4.3.5 @angular/compiler-cli: 4.3.5 @angular/core: 4.3.5 @angular/forms: 4.3.5 @angular/http: 4.3.5 @angular/material: 2.0.0-beta.8 @angular/platform-browser: 4.3.5 @angular/platform-browser-dynamic: 4.3.5 @angular/platform-server: 4.3.5 @angular/router: 4.3.5
Having the same issue with version 1.3.1:
ERROR in ./src/main/web/app/app.module.ts
Module not found: Error: Can't resolve '@module/api'
and
Field 'browser' doesn't contain a valid alias configuration
where @module/api is defined in tsconfig.app.json
@hansl can you take a look?
@hansl @filipesilva @PierreDuc I had the same issue with the library repo and managed to find a workaround. Not sure what is causing this and didn't have much time to look into it. Maybe my workaround helps you out. I have updated @PierreDuc repo ( there are pending pull requests ) with the solution. Now ng serve and aot works properly.
My main changes were to change tsconfig.json to:
{
"compileOnSave": false,
"compilerOptions": {
"paths":{
"@app/*": ["src/app/*"]
},
"baseUrl": ".",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
and tsconfig.app.json to:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"paths":{
"@app/*": ["app/*"]
},
"outDir": "../out-tsc/app",
"baseUrl": ".",
"module": "es2015",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
@nekkon I'm sorry, I can see I did a boo boo while commiting the repo. Didn't actually commit the changes needed to show the error. I've updated my repo now
@PierreDuc Yeah I noticed it. I have already commited those changes based on your description (Repro steps). My pull requests in your repo include your changes and the workaround. If you accept my pull requests you will see my workaround solves this problem. ( until properly fixed by angular-cli team )
@PierreDuc @nekkon It works fine when the path directory is located inside project root. When you move it outside of \src and references in paths as ..\modules, for example, the error still occurs.