Cannot call a namespace ('moment')

See original GitHub issue

My library uses moment import * as moment from 'moment'.

When I run gulp compile I hit this error. Error: Cannot call a namespace ('moment') at error (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:185:14) at Module.error (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:8170:3) at CallExpression.bind (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:6324:17) at eachChild.child (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:5674:34) at keys.forEach.key (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:5685:5) at Array.forEach (native) at ConditionalExpression.eachChild (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:5678:13) at ConditionalExpression.bind (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:5674:8) at eachChild.child (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:5674:34) at keys.forEach.key (C:\SourceCodeNew\IndConsoleSvcProxy\node_modules\rollup\dist\rollup.js:5685:5)

This SO post suggesting change the import to import moment from 'moment' but it doesn’t work for me because I hit another error Module '"C:/SourceCodeNew/IndConsoleSvcProxy/node_modules/moment/moment"' has no default export.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

184reactions
Ismaestrocommented, Jan 8, 2018

My workarround:

import * as moment_ from 'moment';

const moment = moment_;

😃

22reactions
will-wowcommented, Aug 11, 2019

FWIW, I ran into a similar problem, and solved it by adding

"esModuleInterop": true,

to my tsconfig.json. That lets you just import library from "library" from CommonJS libraries, instead of import * as library from 'library', and seems to be a little more forgiving to libraries that otherwise give Typescript trouble

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 8 Moment - Error: Cannot call a namespace ('moment')
This solved a build problem for me with a Vaadin 23.1.6 application. I had two individual .js files in my frontend directory with...
Read more >
Error: Cannot call a namespace ('algoliasearch') - Open Q&A
Issue: Cannot call a namespace ('$')​​ Hi, I'm used the have previous project using rollup/aot successfully. Angular2 projects using JQuery as ...
Read more >
Error from rollup when importing moment.js with rc0 - ionic-v3
I get have a project where use moment.js and imports moment.js using the ... [21:14:54] Error: Cannot call a namespace ('moment') at error ......
Read more >
Errors when using MomentJS in Angular Typescript library ...
Error : Cannot call a namespace ('moment') at error (/Users/chris/angular-library/node_modules/rollup/dist/rollup.js:185:14).
Read more >
TSConfig Option: esModuleInterop - TypeScript
a namespace import like import * as moment from "moment" acts the same as const moment ... hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found