You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?
Type of Issue
Description
Goal: import some fields in
package.json
inside of an Angular library.Two ways:
require
(const version = require('../package.json').version
), but then there is this error duringng build
:import
(import { version } from '../package.json'
), but then there is this error duringng build
: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:
require
.import
.In these branches, just do:
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
Thanks for your help!
Let me know if you need more information. :)
The text was updated successfully, but these errors were encountered: