Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spsaucier-bakkt opened this issue Oct 23, 2020 · 10 comments
Closed

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

spsaucier-bakkt opened this issue Oct 23, 2020 · 10 comments

Comments

@spsaucier-bakkt
Copy link

spsaucier-bakkt commented Oct 23, 2020

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
@iamkun
Copy link
Owner

iamkun commented Oct 24, 2020

A reproduction repo, please?

@spsaucier-bakkt
Copy link
Author

This was resolved when I added dayjs to the app that consumes the library which uses dayjs. Not sure why that would be required.

@rogerprz
Copy link

This was resolved when I added dayjs to the app that consumes the library which uses dayjs. Not sure why that would be required.

Can you explain what you mean? Added where in the app?

@spsaucier-bakkt
Copy link
Author

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

@JenuelDev
Copy link

I dont know if its in codesanbox that's making the error,, but here is the example of an error,,, cant find module.
https://codesandbox.io/s/dayjs-playground-forked-mqd4u?file=/src/index.js
image

@bartosjiri
Copy link

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

@mohas
Copy link

mohas commented Mar 5, 2022

but why?

@vhscom
Copy link

vhscom commented Apr 4, 2022

Using PNPM a related error appeared as:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/src/svelte-headlessui-starter/node_modules/dayjs/plugin/weekOfYear' imported from /src/svelte-headlessui-starter/.svelte-kit/output/server/entries/pages/calendar.svelte.js
Did you mean to import dayjs@1.11.0/node_modules/dayjs/plugin/weekOfYear.js?

Adding .js to the dayjs/plugin imports as suggested by @bartosjiri and mentioned in sveltejs/kit#699 cleared things up.

@vhscom
Copy link

vhscom commented Apr 16, 2022

More about what's causing this error with bare imports: https://nodejs.org/api/esm.html#esm_mandatory_file_extensions
Learned about it here: tailwindlabs/tailwindcss#5089 (comment)

amkige added a commit to amkige/svelte-commerce that referenced this issue Apr 27, 2022
@nahumzs
Copy link

nahumzs commented Jun 19, 2023

but why?

If you are using playwright, It has to do with module resolution, typescript and js, don't remember where I read it but I know is close enough to that situation. I someone can add a more extensive description would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants