Skip to content

Confusing error when preserveSymlinks is missing. #55709

Closed as not planned
Closed as not planned
@axos88

Description

@axos88

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

No

Description

Repro:

  1. git clone a primeng library
  2. npm run build:lib
  3. cd myproject
  4. npm i ../../primeng/dist
  5. import MenubarModule
  6. ng build

Observe: modules cannot be resolved

  1. Try workaround by adding:
    "paths": {
      "primeng/*": ["../node_modules/primeng/*/public_api"]
    },
  1. ng build succeeds
  2. Open application, observe NG0203
main.ts:27 ERROR Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://angular.io/errors/NG0203
  1. spend days debugging the issue
  2. solved by adding preserveSymlinks: true.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

main.ts:27 ERROR Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://angular.io/errors/NG0203

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.3.6
Node: 20.12.2
Package Manager: npm 10.5.0
OS: linux x64

Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1703.6 (cli-only)
@angular-devkit/core         17.3.6 (cli-only)
@angular-devkit/schematics   17.3.6 (cli-only)
@schematics/angular          17.3.6 (cli-only)

Anything else?

preserveSymlinks is not well documented (even after the solution I have no idea what it actually preserves), and the error message anything but points to the missing configuration. A more helpful error message would be great!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions