m.default is not a function (momentjs)
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v16.13.0
- Nuxt Version:
3.0.0-27338323.1e98259
- Package Manager:
npm@8.1.0
- Bundler:
Vite
- User Config:
css
,buildModules
,build
- Runtime Modules:
-
- Build Modules:
@pinia/nuxt@0.1.8
,@nuxtjs/moment@1.6.1
Reproduction
I created a new stackblitz project for reproduction: https://stackblitz.com/edit/github-b92pu2?file=app.vue
Describe the bug
I have a problem with using the library momentjs, but I think this can be a nuxt bug. When I try to use a function of momentjs, I get the 500 error nuxt screen with following error message:
m.default is not a function
at file://./.nuxt/dist/server/server.mjs:10:126
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async renderToString (file://./node_modules/vue-bundle-renderer/dist/index.mjs:248:19)
at async renderMiddleware (file://./.nuxt/nitro/index.mjs:191:20)
Additional context
No response
Logs
(node:8) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/projects/github-b92pu2/node_modules/moment/dist/moment.js:5662
export default hooks;
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (https://github-b92pu2.w.staticblitz.com/blitz.bc2b78560fa0e6097e7f69d4e820659cab64d2c5.js:6:166885)
at Module._compile (https://github-b92pu2.w.staticblitz.com/blitz.bc2b78560fa0e6097e7f69d4e820659cab64d2c5.js:6:167517)
at Object.Module._extensions..js (https://github-b92pu2.w.staticblitz.com/blitz.bc2b78560fa0e6097e7f69d4e820659cab64d2c5.js:6:168239)
at Module.load (https://github-b92pu2.w.staticblitz.com/blitz.bc2b78560fa0e6097e7f69d4e820659cab64d2c5.js:6:166317)
at Function.Module._load (https://github-b92pu2.w.staticblitz.com/blitz.bc2b78560fa0e6097e7f69d4e820659cab64d2c5.js:6:163857)
at _0xb18891.executionFunctionOrLineOffset (https://github-b92pu2.w.staticblitz.com/blitz.bc2b78560fa0e6097e7f69d4e820659cab64d2c5.js:6:738392)
[vite dev] Error loading external "/home/projects/github-b92pu2/node_modules/moment/dist/moment.js".
at eval (file://./.nuxt/dist/server/server.mjs:1997:282)
at async __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:2107:3)
m.default is not a function
at eval (file://./.nuxt/dist/server/server.mjs:19:126)
at async renderToString (file://./node_modules/vue-bundle-renderer/dist/index.mjs:258:19)
at async renderMiddleware (file://./.nuxt/nitro/index.mjs:198:20)
at async handle (file://./node_modules/h3/dist/index.mjs:635:19)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
javascript - SystemJS - moment is not a function - Stack Overflow
unless I try to use momentJS. This is the error I get: TypeError: moment is not a function. This is part of the...
Read more >Moment.js - Maggie's Blog
The moment() Function. When you use the default moment constructor, it will convert the date from the provided offset to the environment's local...
Read more >Docs - Moment.js
Note: Function parameters default to undefined when not passed in. Moment treats moment(undefined) as moment() . Note: Moments are created at evaluation time, ......
Read more >JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the...
Read more >Add - momentjs.com
This is a pretty robust function for adding time to an existing moment. ... 2, 12, 5, 0, 0)); // the day before...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Similiar issue I have on a clean install via
npx nuxi init nuxt3-app
Yup me too. I commented in a similar issue here: https://github.com/nuxt/framework/issues/2601