-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Issue after upgrade using jsdom with optional dependencies #10255
Comments
Looking through the code it appears that this code is the issue, which was added in #9321 vite/packages/vite/src/node/plugins/resolve.ts Lines 397 to 404 in cba13e8
Looking at the node documentation that appears to break the expected behavior for
In reviewing the issue it is trying to fix #6007 it seems a bit ironic that it is trying to fix a similar issue. I wonder if the solution there would be to ask any libraries that use optional deps and cause #6007 to test with |
I have the same issue with this 🥹 - Do you have someway to workaround this? @robpc |
After tracing the issue, I think you could use same lib with me References here: kkomelin/isomorphic-dompurify#54 (comment) |
I'm affected too @harrytran998 sanitize-html isn't supposed to be used on the client |
Thank you for sharing your solution @harrytran998, but that does not work for my case. I need something that mimics the document object and the dom. |
Same here, using
|
Describe the bug
I noticed an issue after upgrading an ssr project with vite from
3.0.4
to3.1.3
. Usingjsdom
in a server side page results in an error about an optional dependency.This error was not present before the upgrade and the optional dependency is not used in the project. If you look at the
jsdom
line referenced above, you seeWhich if you replace the line
require.resolve('canvas');
with something likeYou will get
I RESOLVED CANVAS "__vite-optional-peer-dep:canvas:jsdom"
Obviously that is not what
jsdom
is expecting and causes it to enter the block that requires the missing module.I reproduced this issue by using the starter template
npm create vite-extra@latest -- --template ssr-vanilla
and installingjsdom
and adding an import statement to theentry-server.js
file. Here is a link to that simple project with the issue. Downgrading the version of vite to3.0.4
removes the error.Reproduction
https://github.com/robpc/vite-ssr-optional-dependency-issue
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: