Upgrading a private library named privLib to Angular 13 has been my recent task in order to facilitate the migration of all other projects. However, an issue arises when this library is imported into another project where one of the services utilizes moment and triggers an error stating: "ERROR TypeError: moment is not a function".
When debugging the library in isolation during development mode, no problem is encountered. It compiles without any issues and can be published smoothly. But upon importing it into another project, the mentioned error surfaces if the component from privLib that requires it is used.
Below are snippets from some of the files:
service.ts
import moment from 'moment';
...
moment([dateParsed.getFullYear(), dateParsed.getMonth(), dateParsed.getDate()]) ----> this line triggers the error
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
...
},
"angularCompilerOptions": {
...
}
}
ng-package.json
{
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
"assets": [
"src/assets",
"src/scss/style-mixins.scss"
],
"lib": {
...
},
"allowedNonPeerDependencies": [
"."
]
}
The version of moment being used is ^2.29.1
I have attempted to follow solutions provided by others on this platform, but some seem unresolved or lack proper explanation. Others, unfortunately, do not solve the issue for me.
Edit: Added Package.json
{
"name": "privLib",
"version": "105701.0.3",
"scripts": {
...
},
"dependencies": {
...
},
"devDependencies": {
...
}
}