Ошибка при попытке использовать момент js в библиотеке угловых 7 (То же самое работает в обычном угловом приложении)
Шаги для репликации:
Создать библиотеку углов
ng generate library my-lib
npm install moment --save
в компоненте попробуйте использовать приведенный ниже код
import * as moment from 'moment';
export interface CalendarDate {
mDate: moment.Moment;
}
export class CalenderComponent implements OnInit {
currentDate = moment();
...
Когда мы попробуем ng build my-lib --watch
Сбой при ошибке ниже
Building Angular Package
Building entry point 'student'
Compiling TypeScript sources through ngc
Bundling to FESM2015
BUILD ERROR
Cannot call a namespace ('moment')
Error: Cannot call a namespace ('moment')
at error (D:\Eschool\homework\student\node_modules\rollup\dist\rollup.js:346
0:30)
at Module.error (D:\Eschool\homework\student\node_modules\rollup\dist\rollup
.js:13349:9)
at CallExpression.bind (D:\Eschool\homework\student\node_modules\rollup\dist
\rollup.js:10228:30)
at AssignmentExpression.NodeBase.bind (D:\Eschool\homework\student\node_modu
les\rollup\dist\rollup.js:9183:23)
at AssignmentExpression.bind (D:\Eschool\homework\student\node_modules\rollu
p\dist\rollup.js:9919:31)
at ExpressionStatement$$1.NodeBase.bind (D:\Eschool\homework\student\node_mo
dules\rollup\dist\rollup.js:9183:23)
at BlockStatement$$1.NodeBase.bind (D:\Eschool\homework\student\node_modules
\rollup\dist\rollup.js:9179:31)
at FunctionExpression.NodeBase.bind (D:\Eschool\homework\student\node_module
s\rollup\dist\rollup.js:9183:23)
at MethodDefinition.NodeBase.bind (D:\Eschool\homework\student\node_modules\
rollup\dist\rollup.js:9183:23)
at ClassBody.NodeBase.bind (D:\Eschool\homework\student\node_modules\rollup\
dist\rollup.js:9179:31)
at ClassDeclaration$$1.NodeBase.bind (D:\Eschool\homework\student\node_modul
es\rollup\dist\rollup.js:9183:23)
at ExportNamedDeclaration.bind (D:\Eschool\homework\student\node_modules\rol
lup\dist\rollup.js:10641:30)
at Program.NodeBase.bind (D:\Eschool\homework\student\node_modules\rollup\di
st\rollup.js:9179:31)
at Module.bindReferences (D:\Eschool\homework\student\node_modules\rollup\di
st\rollup.js:13303:18)
at Graph.link (D:\Eschool\homework\student\node_modules\rollup\dist\rollup.j
s:21489:20)
at D:\Eschool\homework\student\node_modules\rollup\dist\rollup.js:21584:19
Compilation failed. Watching for file changes...