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

I was having this exact same error and couldn't figure it out. In our project I had refactored it a bit and created a shared module within one of the features and moved a component from one feature to the shared feature. Unfortunately, and I can't nail down what, but in merging with our dev branch the component actually reappeared in the feature (where it was previously).

This was the cause of the error that's discussed here. It said nothing about that being the issue but I walked through the Git history to figure out what might have caused this error and discovered two duplicate components. I'm guessing the only reason that the error message wasn't more clear in my case is that even though the files were restored to their original location they weren't included in that module.

Marcidius avatar Jan 13 '18 18:01 Marcidius

In my case the problem was, that I imported Router from the wrong package:

I changed import {Router} from '@angular/router/src/router'; to import {Router} from '@angular/router';

then it worked

karsunke avatar Jan 18 '18 08:01 karsunke

There seems to be problems with the way TypeScript imports Angular packages: import { ChangeDetectionStrategy } from '@angular/compiler/src/core'; ng serve with --aot was working, but ng serve without --aot was not. That import was the problem. TypeScript have added a fix for this issue which was included in the nightly build, but it's still not perfect - that's the version I'm using in VSCode It' discussed here it https://github.com/Microsoft/TypeScript/issues/19694

briancodes avatar Jan 20 '18 21:01 briancodes

Had the same issue with accidentally importing EventEmitter from selenium (auto import from vscode... )

Fixed the import, no more error

shairez avatar Jan 22 '18 21:01 shairez

same issue as @jtlthe2

changhuixu avatar Jan 29 '18 18:01 changhuixu

it works for me now. The issue was wrong import path for HttpClientModule

VS code intellisence gives the following import

import { HttpClientModule } from "@angular/common/http/src/module";

While, it should be

import { HttpClientModule } from "@angular/common/http";

changhuixu avatar Jan 29 '18 19:01 changhuixu

I'm now using Typescript version 2.7.0dev in VSCode. Pointing to that local version by configuring "typescript.tsdk" in Workspace Settings. The import problem has been fixed in that version

briancodes avatar Jan 29 '18 19:01 briancodes

For me the same problem occurred when I generate files in one project with (css styles) and moved them to another with scss without renaming extension inside of ts file.

The error is really tricky to follow and find the reason.

laserus avatar Feb 01 '18 14:02 laserus

My solution :

I work on windows machine. And I get this error only on linux machines When the same angular project already work fine on windows .

So I checked and find that the messages Field 'browser' doesn't contain a valid alias configuration

is becuase in some places I used small\upper case that does NOT fit the files/folders. When I fixed it - angular complied successfully.


example - import {myModule} from '../../WrongCamelCase';

where actually - the file was in other camel case.

eyal7773 avatar Feb 08 '18 19:02 eyal7773

ionic app-scripts ^3.1.4 works for me.

I was using 3.1.8 and this error occurred. Roll back to 3.1.4 and try it

tskweres avatar Mar 27 '18 19:03 tskweres

Hi Guys,

I have recently upgraded my all packages along-with application on angular 7. After that few of my packages started failing complaining "Field 'browser' doesn't contain a valid alias configuration".

Module not found: Error: Can't resolve 'D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css' in 'D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent' resolve 'D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css' in 'D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent' using description file: D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\package.json (relative path: .) Field 'browser' doesn't contain a valid alias configuration using description file: D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\package.json (relative path: ./src/styles.css) no extension Field 'browser' doesn't contain a valid alias configuration D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css doesn't exist .ts Field 'browser' doesn't contain a valid alias configuration D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.ts doesn't exist .tsx Field 'browser' doesn't contain a valid alias configuration D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.tsx doesn't exist .mjs Field 'browser' doesn't contain a valid alias configuration D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.mjs doesn't exist .js Field 'browser' doesn't contain a valid alias configuration D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.js doesn't exist as directory D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css doesn't exist [D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css] [D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.ts] [D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.tsx] [D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.mjs] [D:\develop\PoseidonNext\Packages\ng-datacontextselectorcomponent\src\styles.css.js] @ multi ./src/styles.css styles[0]

Before upgrade, everything was working fine. Below, I have pasted package.json.

package.json

{
  "name": "@kognifai/poseidon-ng-datacontextselectorcomponent",
  "version": "2.2.0-alpha.0",
  "description": "Angular implementation of Poseidon data context selector component",
  "author": "Kongsberg Digital",
  "license": "SEE LICENSE IN LICENSE",
  "main": "./dist/bundles/poseidon-ng-datacontextselectorcomponent.umd.js",
  "types": "./dist/kognifai-poseidon-ng-datacontextselectorcomponent.d.ts",
  "scripts": {
    "build": "ng-packagr -p package.json && mkdir dist\\assets && copy /Y .\\src\\assets\\*.* dist\\assets\\",
    "update": "copy /Y package.publish.json dist\\package.json",
    "test": "ng test --watch=false",
    "lint": "ng lint"
  },
  "keywords": [
    "poseidon",
    "data context selector component"
  ],
  "dependencies": {
    "@angular/animations": "^7.1.2",
    "@angular/common": "^7.1.2",
    "@angular/compiler": "^7.1.2",
    "@angular/core": "^7.1.2",
    "@angular/forms": "^7.1.2",
    "@angular/http": "^7.1.2",
    "@angular/platform-browser": "^7.1.2",
    "@angular/platform-browser-dynamic": "^7.1.2",
    "@angular/router": "^7.1.2",
    "@kognifai/poseidon-datacontextservice": "^2.2.0-alpha.0",
    "@kognifai/poseidon-dropdown-directive": "^2.2.0-alpha.0",
    "@kognifai/poseidon-ng-datacontextservice": "^2.2.0-alpha.0",
    "core-js": "^2.5.4",
    "rxjs": "~6.3.3",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.11.2",
    "@angular/cli": "^7.1.2",
    "@angular/compiler-cli": "^7.1.2",
    "@angular/language-service": "^7.1.2",
    "@kognifai/poseidon-script-version-bump": "^2.2.0-alpha.0",
    "@kognifai/poseidon-tslint": "^2.2.0-alpha.0",
    "@types/jasmine": "^3.3.0",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^10.12.12",
    "codelyzer": "^4.5.0",
    "core-js": "^2.6.0",
    "jasmine-core": "^3.3.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^3.1.3",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.4",
    "karma-jasmine": "^2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "ng-packagr": "^4.4.5",
    "protractor": "^5.4.1",
    "ts-node": "^7.0.1",
    "tsickle": "^0.34.0",
    "tslint": "^5.11.0",
    "typescript": "~3.1.6"
  },
  "ngPackage": {
    "lib": {
      "entryFile": "public_api.ts",
      "externals": {
        "@kognifai/poseidon-datacontextservice": "DataContextService",
        "@kognifai/poseidon-ng-datacontextservice": "DataContextNgService",
        "@kognifai/poseidon-dropdown-directive": "DropdownDirective"
      }
    },
    "deleteDestPath": false,
    "whitelistedNonPeerDependencies": [
      "."
    ]
  }
}

tsconfig.json

    "extends": "./tsconfig.base.json",
    "compileOnSave": false,
    "exclude": [
      "node_modules",
      "dist",
      "test.ts",
      "**/*.spec.ts"
    ],
    "compilerOptions": {
      "outDir": "dist"
    },
    "angularCompilerOptions": {
      "strictMetadataEmit": true
    },
    "include": [
        "public_api.ts",
        "./src/polyfills.ts",
        "./src/**/*"
    ],
  }
  `
tsconfig.base.json
`{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom",
      "scripthost",
      "es2015.promise"
    ]
  }
}

tsconfig.app.json

  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

Kindly let me know, if there is anything needs to be changed from my side.

Thanks, Rahul

rahulsahay19 avatar Dec 15 '18 07:12 rahulsahay19

My solution was simply add alias to webpack config

   alias: { 
        "@providers": path.resolve('./src/providers'),
        "@app": path.resolve('./src/app'),
        "@pages": path.resolve('./src/pages'),
        "@pipes": path.resolve('./src/pipes')
    }

Juanperezc avatar Jan 03 '19 00:01 Juanperezc

@Juanperezc I don't have webpack config and now we can't eject as well. I just migrated my app on angular 7 and it suddenly started failing. I don't have any external dependency as well!

rahulsahay19 avatar Jan 04 '19 13:01 rahulsahay19

@rahulsahay19 I have about the same error as you, except with my own scss files. And also it only do it when I run my unit tests (using jasmine). My app serves fine though. Didn't try it to build with prod config yet.

proAppleEater avatar Jan 23 '19 15:01 proAppleEater

So I have just found a fix for my problem, so you might want to check it too if it was similar to mine : in angular.json, I had to change the short styles path for the full one before "styles": [ "src/styles/style.scss" ],

after "styles": [ "apps/our-project-name/src/styles/style.scss" ], So you might want to revise your angular.json. I hope this can help.

proAppleEater avatar Jan 23 '19 15:01 proAppleEater

This seems like an old issue and there are a lot of potential solutions above. Can we close as fixed in the latest CLI or I'm missing something?

mgechev avatar Jan 23 '19 19:01 mgechev

We cannot. This is still an issue with 6.0.8:

"devDependencies": {
    "@angular-devkit/build-angular": "^0.13.8",
    "@angular/cli": "^6.0.8",
    "@types/core-js": "0.9.34",
    "@types/file-saver": "0.0.1",
    "@types/jasmine": "2.5.38",
    "@types/jwt-decode": "2.2.1",
    "@types/node": "6.0.45",
    "angular2-template-loader": "^0.5.0",
    "awesome-typescript-loader": "3.4.1",
    "css-loader": "^0.28.11",
    "es5-shim": "^4.5.10",
    "gulp": "^4.0.0",
    "gulp-cli": "^2.0.1",
    "gulp-csso": "^3.0.1",
    "gulp-csv-to-json": "^0.1.1",
    "gulp-less": "^4.0.0",
    "gulp-newer": "^1.4.0",
    "gulp-prune": "^0.2.0",
    "gulp-run-command": "0.0.9",
    "gulp-watch": "^5.0.1",
    "jasmine-core": "^2.8.0",
    "karma": "^2.0.5",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-es5-shim": "0.0.4",
    "karma-es6-shim": "^1.0.0",
    "karma-jasmine": "^1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-typescript": "^3.0.13",
    "karma-typescript-angular2-transform": "^1.0.2",
    "karma-webpack-preprocessor": "^1.0.1",
    "less": "^3.8.1",
    "less-loader": "^4.1.0",
    "ngx-spec": "^1.0.1",
    "nodemon": "^1.18.3",
    "rxjs-tslint": "^0.1.5"
  },

In my case, it appears to be a missing style.css file, which it's never complained about until I upgraded.

bh-hsi avatar May 16 '19 14:05 bh-hsi

In my case this is what did the trick, I changed this part of my code (angular.json) "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", "assets": ["src/favicon.ico", "src/assets"], "styles": ["src/styles.css"], "scripts": [] } },

to this

"test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", "assets": ["src/favicon.ico", "src/assets"], "styles": [], "scripts": [] } },

This issue seems to contain reports of a similar error on different situation from several different versions of Angular CLI. It doesn't include a lot of reproductions however, so it's very hard for us to pinpoint and fix the problem.

If you're still experiencing this error today can you open a new issue with a reproduction please? Thank you.

filipesilva avatar Oct 01 '19 16:10 filipesilva

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.