angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Field 'browser' doesn't contain a valid alias configuration

Open mark-holmes opened this issue 9 years ago • 40 comments

The build fails when trying to perform a build involving a requirejs dependency which also requires other files.

In this case the following error appears: Field 'browser' doesn't contain a valid alias configuration

The error does not occur if the required file dependency has no dependencies, and it appears to have been introduced after 1.2.6. This affects both jit & aot builds.

Bug Report or Feature Request (mark with an x)

- [ X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.7 node: 8.5.0 os: darwin x64 @angular/animations: 4.4.5 @angular/common: 4.4.5 @angular/compiler: 4.4.5 @angular/core: 4.4.5 @angular/forms: 4.4.5 @angular/http: 4.4.5 @angular/platform-browser: 4.4.5 @angular/platform-browser-dynamic: 4.4.5 @angular/router: 4.4.5 @angular/cli: 1.4.7 @angular/compiler-cli: 4.4.5 @angular/language-service: 4.4.5 typescript: 2.3.4

Repro steps.

Example Repository Using 1.2.6 of the cli will build correctly.

  • ng new project
  • add requirejs
  • add path inside tsconfig
  • require a file using the path

At this stage the project builds and runs as expected.

However if the required file has other dependencies they will not be resolved and the build breaks.

The log given by the failure.

log.txt

Desired functionality.

Nested modules should resolve correctly.

Mention any other details that might be useful.

The regression was introduced after 1.2.6. The example repo was built with cli 1.4.7.

Related Issue Related Issue 7341

mark-holmes avatar Oct 13 '17 01:10 mark-holmes

What you are describing is expected behavior. tsconfig settings affect .ts files. Webpack handles module resolution within javascript files and it cannot resolve the module in question. Which makes sense since required-module/strings isn't a package and is not in the app's root. (The two places webpack looks for module dependencies.) If this worked previously, it could really be considered a defect.

To make it work there are several options:

  • change the dependency to ./strings
  • change the file extension of logger.js to logger.ts
  • move the entire directory inside the root (src in this case)
  • make required-module an actual package and link it

Also, as an aside, requirejs is unused and not needed.

clydin avatar Oct 13 '17 03:10 clydin

Thanks clydin.

This is unfortunate if it is to be considered a defect as I am unable to act on any of your suggestions without incurring significant work.

At the end of the day I need to be able to alias a javascript path, which worked up to v1.2.6

Normally this would be solved by editing the alias field of the webpack config.

#7287 Seems to be related.

mark-holmes avatar Oct 13 '17 05:10 mark-holmes

I am getting this error in the latest CLI, with rxjs 5.4.2.....

Field 'browser' doesn't contain a valid alias configuration C:\Users\tpadle01\IdeaProjects\onland-ui\src\rxjs\operators.js doesn't exist as directory C:\Users\tpadle01\IdeaProjects\onland-ui\src\rxjs\operators doesn't exist looking for modules in C:\Users\tpadle01\IdeaProjects\onland-ui\src using description file: C:\Users\tpadle01\IdeaProjects\onland-ui\package.json (relative path: ./src) Field 'browser' doesn't contain a valid alias configuration after using description file: C:\Users\tpadle01\IdeaProjects\onland-ui\package.json (relative path: ./src) using description file: C:\Users\tpadle01\IdeaProjects\onland-ui\package.json (relative path: ./src/rxjs/operators) no extension

TylerDev6 avatar Nov 01 '17 16:11 TylerDev6

I am getting the issue @TylerDev6 mentioned... It seems that instead of looking into the /node_modules folder, it's searching within the src folder...

This started happening after upgrading to angular v5, angular cli 1.5 and typescript 2.4.2

jeanpaulattard avatar Nov 06 '17 14:11 jeanpaulattard

Angular 5 requires rxjs 5.5+. Please note that this is unrelated to the original issue. If you continue to experience the issue, please open a separate issue.

clydin avatar Nov 06 '17 14:11 clydin

i started getting this error after i upgraded to angular 5 and angular cli 1.5.0

Angular CLI: 1.5.0 Node: 8.9.0 OS: darwin x64 Angular: 5.0.0 ... animations, common, compiler, core, forms, http ... language-service, platform-browser, platform-browser-dynamic ... platform-server, router

@angular/cli: 1.5.0 @angular/compiler-cli: 4.4.6 @angular/tsc-wrapped: 4.4.6 @angular-devkit/build-optimizer: 0.0.32 @angular-devkit/core: 0.0.20 @angular-devkit/schematics: 0.0.35 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.0 @schematics/angular: 0.1.0 typescript: 2.6.1 webpack: 3.8.1

mrusmanali avatar Nov 07 '17 07:11 mrusmanali

I had the exactly same error here. Field 'browser' doesn't contain a valid alias configuration

@angular/cli: 1.6.0 @angular/compiler-cli: 5.1.0

Jeff-Li-Realster avatar Dec 08 '17 21:12 Jeff-Li-Realster

Also I was getting this error when html markup is invalid. Just make your html closing tag invalid, in my case I forgot to change closing main tag.

<app-header></app-header>
<main role="main" class="container">
    <router-outlet></router-outlet>
</div>
<app-footer></app-footer>

Using ng serve --aot I got useless Field 'browser' doesn't contain a valid alias configuration error, but switching to ng serve I got expected error saying that main tag is not closed.

anjmao avatar Dec 09 '17 19:12 anjmao

Same error here, we rollback the npm update today to fix, working versions:

Angular CLI: 1.5.5
Node: 8.5.0
OS: linux x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... tsc-wrapped

@angular/cli: 1.5.5
@angular-devkit/build-optimizer: 0.0.34
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.39
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.5
@schematics/angular: 0.1.9
typescript: 2.3.4
webpack-dev-server: 2.9.5
webpack: 3.8.1

Bad versions (cause the related error browser):

Angular CLI: 1.6.0
Node: 8.5.0
OS: linux x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... tsc-wrapped

@angular/cli: 1.6.0
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.41
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0
@schematics/angular: 0.1.10
@schematics/schematics: 0.0.10
typescript: 2.3.4
webpack-dev-server: 2.9.7
webpack: 3.10.0

Hope this help.

tecnocat avatar Dec 11 '17 15:12 tecnocat

Hi, tecnocat, Thank you so much. your solution worked for me.

geenino avatar Dec 12 '17 10:12 geenino

Our problem was only the @ng-bootstrap/ng-bootstrap library, we have the version 1.0.0-beta.6 that broken everything and need to downgrade to the version 1.0.0-beta.5 that's works fine for us.

We fix with this commands:

rm -rf node_modules/ package-lock.json
npm install
npm install @ng-bootstrap/[email protected]

And everything works great.

tecnocat avatar Dec 12 '17 11:12 tecnocat

I got this error when I hade my page modules declared in both src/app/app.module.ts and their specific module e.g. src/pages/test/test.module.ts. Running ngc gave a much better error diagnosis:

./node_modules/.bin/ngc
Error: Type TestPage in /src/pages/test/test.ts is part of the declarations of 2 modules: 
AppModule in /src/app/app.module.ts and TestPageModule in /src/pages/test/test.module.ts! 
Please consider moving TestPage in /src/pages/test/test.ts to a higher module that imports 
AppModule in /src/app/app.module.ts and TestPageModule in /src/pages/test/test.module.ts. You 
can also create a new NgModule that exports and includes TestPage in /src/pages/test/test.ts 
then import that NgModule in AppModule in /src/app/app.module.ts and TestPageModule in 
/src/pages/test/test.module.ts.

I would suggest running ngc if you are getting an weird webpack build error like this as it seems like various issues are causing this specific misleading error.

CoreyCole avatar Dec 13 '17 07:12 CoreyCole

NOTE: Definitely commit to git before you run ngc as it adds a bunch of files you don't want added to your repo i.e.

 create mode 100644 src/app/app.component.js
 create mode 100644 src/app/app.component.js.map
 create mode 100644 src/app/app.component.metadata.json
 create mode 100644 src/app/app.component.ngfactory.js
 create mode 100644 src/app/app.component.ngfactory.js.map
 create mode 100644 src/app/app.component.ngsummary.json
 create mode 100644 src/app/app.module.js
 create mode 100644 src/app/app.module.js.map
 create mode 100644 src/app/app.module.metadata.json
 create mode 100644 src/app/app.module.ngfactory.js
 create mode 100644 src/app/app.module.ngfactory.js.map
 create mode 100644 src/app/app.module.ngsummary.json
 create mode 100644 src/app/main.js
 create mode 100644 src/app/main.js.map
 create mode 100644 src/app/main.metadata.json
 create mode 100644 src/app/main.ngsummary.json

CoreyCole avatar Dec 13 '17 08:12 CoreyCole

A totally different problem here, we had some compiler errors (imports were incorrect, VSCode showed that nicely) in a lazy-loaded feature module. However, those went entirely undetected by ng serve while ng serve --aot would fail with this cryptic error message.

I think what needs to be done here is a better surfacing of the underlying error, it appears the error message discussed in this issue masks all sorts of different underlying errors.

JohannesRudolph avatar Dec 13 '17 11:12 JohannesRudolph

The same issue, Angular 5 is not showing proper error message and many breaking changes :(

nsksaisaravana avatar Dec 14 '17 00:12 nsksaisaravana

I downgraded to ng 5.0.5 to be able to see the underlying errors(as suggested here).

kinkoazc avatar Dec 14 '17 07:12 kinkoazc

I think the error messages are not too good and say nothing about the issue itself, in my case I solved this issue in tsconfig, to my app config I added an alias in my config and this alias contains a path to a module file, and this path is relative so I need to make the following changes:

Before:

"paths": {
  "@app/config": ["src/config/environment.dev.ts"]
}

After:

"paths": {
  "@app/config": ["./src/config/environment.dev.ts"]
}

Just './' and AoT is working again. Hope it helps.

leonardosalles avatar Dec 15 '17 18:12 leonardosalles

Same error message here. Solved moving ActivatedRoute import from @angular/router/src/router_state to @angular/router. The import has been automatically generated by VSCode autoimport feature.

JosepAlacid avatar Dec 27 '17 11:12 JosepAlacid

Thanks @JosepAlacid, I had the same problem with @angular/platform-browser autoimporting as @angular/platform-browser/src/security/dom_sanitization_service in VS Code. Looks like there's an issue for it here: https://github.com/Microsoft/TypeScript/issues/19888

aeslinger0 avatar Dec 28 '17 14:12 aeslinger0

@JosepAlacid and @aeslinger0, I too had this problem with auto-import in Visual Studio Code. This was fixed by changing... import { HttpClientModule } from '@angular/common/http/src/module'; ...to... import { HttpClientModule } from '@angular/common/http'; ...in my app.module.ts.

For anyone else who initially got lost in the error message like I did, everything you need is in the first two lines. The first line has the file the import was incorrectly auto-imported, and the second line is which path doesn't have the module you are trying to import. ERROR in ./src/app/app.module.ts Module not found: Error: Can't resolve '@angular/common/http/src/module'

jtlthe2 avatar Jan 01 '18 22:01 jtlthe2