question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module 'dayjs/plugin/timezone' in sub-module

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
bartosjiricommented, Nov 18, 2021

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';

4reactions
spsaucier-bakktcommented, Oct 15, 2021

That’s a good question 🤔 I wrote that very vaguely, and I don’t remember what I meant.

Read more comments on GitHub >

github_iconTop 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 >

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