(note: running Angular 8 and Node version 12.15.0)
UPDATE: It appears to be a bug, so I have opened an issue here
I'm in the process of developing a library where I have defined the path @env
in the tsconfig.json
:
{
"compilerOptions": {
[...]
"paths": {
"@env/*": [
"projects/mylib/src/environments/*"
]
}
}
In my code, I reference the environment like this:
import { environment } from '@env/environment';
However, it seems that the compiler is getting confused because when I try to build using (ng build my-lib
), I receive the following warning message:
WARNING: No name was provided for external module '@env/environment' in output.globals – guessing 'environment'
Furthermore, importing the module into a project results in this compilation error:
ERROR in The target entry-point "my-lib" has missing dependencies:
- @env/environment
It seems like @env/environment
is being treated as an external module. How can I resolve this issue?
Steps to reproduce:
Note: I have created a ready-to-use SSCCE available here
- Create a new project (
ng new acme
) with basic options: no routing, plain CSS styling. - Within the project, create a library (
ng g generate library my-lib
) - Under
projects/my-lib/src
, create a folderenvironments
containing 2 files:environment.ts
andenvironments.prod.ts
- Configure
by adding the block as shown below:projects/my-lib/tsconfig.lib.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
],
"paths": {
"baseUrl": [ "./" ],
"@env/*": [ "projects/my-lib/src/environments/*" ]
}
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
],
}
Your project structure should resemble the following:
.
├── angular.json
├── browserslist
├── e2e
│ ├── protractor.conf.js
│ ├── src
│ │ ├── app.e2e-spec.ts
│ │ └── app.po.ts
│ └── tsconfig.json
├── karma.conf.js
├── package.json
├── package-lock.json
├── projects
│ └── my-lib
│ ├── karma.conf.js
│ ├── ng-package.json
│ ├── package.json
│ ├── README.md
│ ├── src
│ │ ├── environments
│ │ │ ├── environment.prod.ts
│ │ │ └── environment.ts
│ │ ├── lib
│ │ │ ├── my-lib.component.spec.ts
│ │ │ ├── my-lib.component.ts
│ │ │ ├── my-lib.module.ts
│ │ │ ├── my-lib.service.spec.ts
│ │ │ └── my-lib.service.ts
│ │ ├── public-api.ts
│ │ └── test.ts
│ ├── tsconfig.lib.json
│ ├── tsconfig.lib.prod.json
│ ├── tsconfig.spec.json
│ └── tslint.json
├── README.md
├── src
│ ├── app
│ │ ├── app.component.css
│ │ ├── app.component.html
│ │ ├── app.component.spec.ts
│ │ ├── app.component.ts
│ │ └── app.module.ts
│ ├── assets
│ ├── environments
│ │ ├── environment.prod.ts
│ │ └── environment.ts
│ ├── favicon.ico
│ ├── index.html
│ ├── main.ts
│ ├── polyfills.ts
│ ├── styles.css
│ └── test.ts
├── tsconfig.app.json
├── tsconfig.json
├── tsconfig.spec.json
└── tslint.json
Now,
- To reproduce the warning, build the library:
ng build my-lib
- To reproduce the error, import
MyLibModule
into the main project and build it:ng build