Cannot find module 'dayjs/plugin/timezone' in sub-module
See original GitHub issueDescribe the bug
Similar to #1135, getting Cannot find module 'dayjs/plugin/timezone' from 'node_modules/my-module'
when importing my module from elsewhere and trying to run tests.
The plugin works properly within the code where it’s used, but this issue appears when importing it as node_module.
Expected behavior Able to import dayjs plugins and use them in code used as a sub-module.
Usage in sub-module:
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import dayjsIsBetween from 'dayjs/plugin/isBetween';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(customParseFormat);
dayjs.extend(dayjsIsBetween);
dayjs.extend(utc);
dayjs.extend(timezone);
Information
- Day.js Version: v1.9.4
- OS: Mac
- Browser Terminal
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Cannot find module 'dayjs/plugin/timezone' in sub ... - Issuehunt
The plugin works properly within the code where it's used, but this issue appears when importing it as node_module.
Read more >Timezone
Timezone adds dayjs.tz .tz .tz.guess .tz.setDefault APIs to parse or display between time zones. var utc = require('dayjs/plugin/utc') var timezone ...
Read more >dayjs-plugin-utc - npm
utc plugin for dayjs. Latest version: 0.1.2, last published: 3 years ago. Start using dayjs-plugin-utc in your project by running `npm i ...
Read more >You might not need date-fns - DEV Community
It perfectly supports native IANA timezone and locale formatting. It means that you can not include locales in the bundle at all.
Read more >dayjs() is in the wrong timezone - javascript - Stack Overflow
Simply using the utc plugin without the timezone plugin somehow had the desired effect. import utc from 'dayjs/plugin/utc'; day.extend(utc); ...
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 Free
Top 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
I had a similar problem when compiling a production build of a SvelteKit app. The solution, as console error has suggested, was to add the
.js
extension to the import path:Example:
import timezone from 'dayjs/plugin/timezone';
->import timezone from 'dayjs/plugin/timezone.js';
That’s a good question 🤔 I wrote that very vaguely, and I don’t remember what I meant.