在包含MomentJS时,我遇到了各种构建问题。
我首先使用
import moment from 'moment';
将moment引入组件,但这会在构建时产生以下错误;[17:26:28] Starting 'ngc'...
Error at /Users/chris/angular-library/.tmp/components/my-library/my-component.component.ts:6:8: Module '"/Users/chris/my-library/node_modules/moment/moment"' has no default export.
我发现这个stackoverflow问题,上面说要使用import * as moment from 'moment';
,然而我用了这个却出现了以下错误:
'moment' is imported by build/components/my-component.component.js, but could not be resolved – treating it as an external dependency
events.js:182
throw er; // Unhandled 'error' event
^
Error: Cannot call a namespace ('moment')
at error (/Users/chris/angular-library/node_modules/rollup/dist/rollup.js:185:14)
据我所知,这似乎是唯一的两个选项,但我都无法使其正常工作,我错过了什么吗?
编辑
我已将此问题添加到库的Github存储库中,其中包含最简化的复制步骤。
yo
和generator-angular2-library
才能有机会重现您的问题吗? - Sergey