-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
Error [ERR_UNSUPPORTED_DIR_IMPORT] importing date-fns/locale #205
Comments
@ChrisGV04 since we move to You can check this issue, there are some hints there about esm support: #201 |
@ChrisGV04 maybe you can check https://nodejs.org/api/intl.html, you can use |
@userquin Thank you very much for both of your replies! I made some more research with the information you shared about esm and I was able to fix it by changing the import path of the locale to the following:
That seems to work fine and it also builds the project without any issues. If this is bad practice or there's some reason for not doing that, please let me know! Thank you very much. I also tried Intl and it does work for most of my needs, but unfortunately I do need date-fns for more than just formatting dates. But thanks for the recommendation, I will certainly start using it more! |
Importing the dependency this way you are bundling the full dependency: You can try building your app, check the chunks size, then modify the Don't forget to undo changes made on |
Hi! I'm currently using date-fns on my vite / vue app for date formatting and I'm also using the locale for spanish. For some reason when I run
npm run build
I get the error:Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/my-project-directory/node_modules/date-fns/locale' is not supported resolving ES modules imported from /my-project-directory/.vite-ssg-temp/main.mjs
and it suggestsDid you mean to import date-fns@2.28.0/node_modules/date-fns/locale/index.js?
This is weird because I have been using this exact same code with older versions and it worked perfectly, also when I run
npm run dev
everything works fine. The last version of vite-ssg I tried and builds with no problem is 0.17.6. I'm also using date-fns version 2.28.0This is my build script in the package.json:
"build": "cross-env NODE_ENV=production vite-ssg build"
The text was updated successfully, but these errors were encountered: