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

[Guidance] Deep import issues #1067

Closed
arpowers opened this issue Nov 12, 2020 · 4 comments
Closed

[Guidance] Deep import issues #1067

arpowers opened this issue Nov 12, 2020 · 4 comments

Comments

@arpowers
Copy link
Contributor

This is a similar issue to the one in #1041 ... In my case, I'm trying to include: dayjs/plugin/relativeTime

As described here on the page for RelativeTime by DayJS they want you to include a deeply nested plugin from their dep .

However, in Vite I can't seem to import the module. Getting the following:

[vite] Avoid deep import "dayjs/plugin/relativeTime" (imported by /@modules/@factor/api/time.ts)
because "dayjs" has been pre-optimized by vite into a single file.
Prefer importing directly from the module entry:

  import { ... } from "dayjs"

I need some clarification as to how this should be handled.

@aleclarson
Copy link
Member

Have you tried this in Vite config?

optimizeDeps: {
  exclude: ['dayjs'],
}

@arpowers
Copy link
Contributor Author

Ya it's in CJS format so needs to be optimized

@aleclarson
Copy link
Member

For dayjs in particular, you're in luck.

import relativeTime from 'dayjs/esm/plugin/relativeTime'

For other libraries, you can fork them and import the original source, as long as it uses ES modules.

import relativeTime from 'dayjs/src/plugin/relativeTime'

@arpowers
Copy link
Contributor Author

@aleclarson thanks !

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants