Issue
I've just started to build my own library for Angular. First I added a service; I can build the lib problem-free.
For this service, however, I have moved a constant to a file called tokens.ts to which the service now references. J
Now the build fails with the following message:
------------------------------------------------------------------------------
Building entry point 'mylib'
------------------------------------------------------------------------------
√ Compiling with Angular sources in Ivy partial compilation mode.
× Generating FESM2020
'SOME_VALUE' is not exported by dist\mylib\esm2020\lib\tokens.mjs, imported by dist\mylib\esm2020\lib\services\mysuperservice.service.mjs
Process finished with exit code 1
The tokens.ts:
export declare const SOME_VALUE: ...
The mentioned service:
import {SOME_VALUE} from "../tokens";
@Injectable({
providedIn: 'root',
})
export class MySuperService{
//...
My tsconfig.lib.json:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": []
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
My tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"paths": {
"common": [
"dist/mylib/mylib",
"dist/mylib"
]
},
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": [
"es2020",
"dom"
]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
My public-api.ts:
export * from './lib/tokens';
export * from './lib/mylib/mysuperservice.service';
export * from './lib/mylib.module';
My project-tree:
I could imagine that this has something to do with my TS compiler options, since the error message mentions .mjs files. However, I have no idea where the problem could be.
Can you help me with that?
Solution
As @jboot mentioned, the problem was indeed that I was declaring a type; not a concret instance.
Correct way:
export const SOME_VALUE= new InjectionToken<SomeType>('some description');
Thanks for that!
Answered By - EchtFettigerKeks

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.