Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when importing package.json in a library #1602

Open
darondel-yoobic opened this issue Apr 14, 2020 · 1 comment
Open

Errors when importing package.json in a library #1602

darondel-yoobic opened this issue Apr 14, 2020 · 1 comment
Labels

Comments

@darondel-yoobic
Copy link

darondel-yoobic commented Apr 14, 2020

Type of Issue

[X] Bug Report
[ ] Feature Request

Description

Goal: import some fields in package.json inside of an Angular library.

Two ways:

  • Import it via require (const version = require('../package.json').version), but then there is this error during ng build:
ERROR: Could not resolve '../package.json' from dist/library/esm2015/environment.js
An unhandled exception occurred: Could not resolve '../package.json' from dist/library/esm2015/environment.js
  • Import it via import (import { version } from '../package.json'), but then there is this error during ng build:
An unhandled exception occurred: projects/library/src/environment.ts:1:25 - error TS6059: File '<library-path>/package.json' is not under 'rootDir' '<library-path>/src'. 'rootDir' is expected to contain all source files.

1 import { version } from '../package.json';

The first usage is working if you fix the version of @rollup/plugin-commonjs to 11.0.2. It fails with 11.1.0.

How To Reproduce

I compiled those cases in a repository:

In these branches, just do:

npm install
ng build --project library

You should see the error.

Expected Behaviour

In the first case, it seems that there is an issue with Rollup.
The second one seems to be more Typescript friendly but cannot use it at the moment. Is it possible to achieve it?

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: 9.1.1
@angular/compiler: 9.1.1
rollup: 2.6.1
tsickle:
typescript: 3.8.3

Thanks for your help!
Let me know if you need more information. :)

@cjz9032
Copy link

cjz9032 commented Nov 17, 2022

same issue, I only have a not ideal workaround,
@ts-ignore
import packageJson from '../../package.json'

You may noticed, this only work when it as a output in dist folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants