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

Investigate root cause for vite 4.3.x can't build date-fns/locale in ssr (temp. patched) #12997

Open
7 tasks done
indeyets opened this issue Apr 25, 2023 · 7 comments
Open
7 tasks done
Labels
feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@indeyets
Copy link

Describe the bug

I'm importing locales from date-fns like this: import { enGB, es, de } from "date-fns/locale"; in my code.

It worked fine with vite 4.2.x, but both 4.3.0 and 4.3.1 replace the "from" part with … from "s"; which server, once it runs, can not find, for obvious reasons.

Reproduction

https://github.com/indeyets/vite-bug

Steps to reproduce

run npm install followed by npm test

System Info

I reproduced it both on macos and linux.

  System:
    OS: macOS 13.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 482.73 MB / 32.00 GB
    Shell: 3.6.1 - /usr/local/bin/fish
  Binaries:
    Node: 19.9.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.6.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Edge: 112.0.1722.58
    Firefox: 110.0
    Safari: 16.5
    Safari Technology Preview: 16.4

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red sapphi-red added p4-important Violate documented behavior or significantly improves performance (priority) feat: ssr regression The issue only appears after a new release labels Apr 25, 2023
@bluwy
Copy link
Member

bluwy commented Apr 26, 2023

Does it work in Vite 4.2? Using 4.2 and running your repro I get:

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/bjorn/Work/repros/vite-3-date-fns/node_modules/date-fns/locale' is not supported resolving ES modules imported from /Users/bjorn/Work/repros/vite-3-date-fns/dist/server.js
Did you mean to import date-fns/node_modules/.pnpm/date-fns@2.29.3/node_modules/date-fns/locale/index.js?

@indeyets
Copy link
Author

indeyets commented Apr 26, 2023

@bluwy good point. it works in my complex app, but not here. I reproduced bad behaviour without reproducing good.

I'll see what I can do 🤔

but it looks like @btea figured out the problem anyway?

@bluwy
Copy link
Member

bluwy commented Apr 26, 2023

I wasn't sure if the PR was the right fix, and in any case we should fix to report the right error as before instead. But happy to look into it again if you manage to find out how it works before. FWIW I tried fiddling with ssr.external and ssr.noExternal in the repro but I can't repro that case where it works in 4.2 but not 4.3.

@sun0day
Copy link
Member

sun0day commented Apr 26, 2023

btea's PR makes the Vite4.3's resolve behavior the same as Vite4.2's, but it seems like there is another potential bug as bluwy said. Could you provide your complex app or maybe vite.config.js? @indeyets

@jaybe78
Copy link

jaybe78 commented Apr 26, 2023

Hello,

I'm also working on a SSR application where the server is built using webpack.
Since I've upgrade to 4.3 version I'm also getting that issue

Module not found: Error: Can't resolve 's' in '/Users/jean-bricerougeot/Documents/bulbshare-web-app-react/websites/my.bulbshare.com/dist/server/src/renderer'
 @ ./dist/server/pageFiles.mjs
 @ ./dist/server/importBuild.cjs 4:21-46
 @ ../../node_modules/@brillout/vite-plugin-import-build/dist/autoImporter.js 2:34-110 8:37-121
 @ ../../node_modules/@brillout/vite-plugin-import-build/dist/loadServerBuild/index.js 9:21-47
 @ ../../node_modules/@brillout/vite-plugin-import-build/loadServerBuild.js 1:0-50
 @ ../../node_modules/vite-plugin-ssr/dist/cjs/node/runtime/globalContext/loadImportBuild.js 4:26-87
 @ ../../node_modules/vite-plugin-ssr/dist/cjs/node/runtime/globalContext.js 5:26-68
 @ ../../node_modules/vite-plugin-ssr/dist/cjs/node/runtime/renderPage.js 10:24-50

I confirm it works correctly When I downgrade to 4.2.0

@sun0day
Copy link
Member

sun0day commented Apr 26, 2023

Could you provide a mini-repro? @jaybe78

@bluwy
Copy link
Member

bluwy commented Apr 30, 2023

@DMOAbove that looks like a different issue and an expected one. And I don't think v4.2.2 could be regressing it, but if you found it so, please create a new issue with the repro. Thanks!


An update for this issue. It was fixed at #13010 but the fix can be improved further based on the root cause, so it's left opened. Updating the labels for now.

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) and removed p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release labels Apr 30, 2023
@patak-dev patak-dev changed the title vite 4.3.x can't build (ssr) date-fns/locale Investigate root cause for vite 4.3.x can't build date-fns/locale in ssr (temp. patched) May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

5 participants