Cannot install JSDOM with Kit
See original GitHub issueDescribe the bug
I am attempting to add JSDOM to a Kit app in order to do some simple web scraping in one of my routes. JSDOM fails with the following errors when attempting to import:
ENOENT: no such file or directory, open '__vite-optional-peer-dep:canvas:jsdom'
Error: ENOENT: no such file or directory, open '__vite-optional-peer-dep:canvas:jsdom'
at Object.openSync (node:fs:599:3)
at Object.readFileSync (node:fs:467:35)
at Module._extensions..js (node:internal/modules/cjs/loader:1136:18)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
at Module.require (node:internal/modules/cjs/loader:1021:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/Users/danawoodman/code/repros/sk-jsdom/node_modules/jsdom/lib/jsdom/utils.js:158:18)
at Module._compile (node:internal/modules/cjs/loader:1119:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
Installing canvas gets me:
dlopen(/Users/danawoodman/code/repros/sk-jsdom/node_modules/canvas/build/Release/canvas.node, 0x0001): symbol not found in flat namespace (_cairo_fill)
Error: dlopen(/Users/danawoodman/code/repros/sk-jsdom/node_modules/canvas/build/Release/canvas.node, 0x0001): symbol not found in flat namespace (_cairo_fill)
at Module._extensions..node (node:internal/modules/cjs/loader:1203:18)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
at Module.require (node:internal/modules/cjs/loader:1021:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/Users/danawoodman/code/repros/sk-jsdom/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (node:internal/modules/cjs/loader:1119:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
I’ve attempted alternatives to JSDOM like happy-dom and linkedom but neither can handle the HTML I’m scraping.
I created a repro with Vanilla Vite using their generator and importing JSDOM works fine, so I am assuming this has something to do with Kit?
Here is the relevant line in my repro.
Reproduction
https://github.com/danawoodman/sveltekit-jsdom-repro
Logs
see above
System Info
System:
OS: macOS 12.5.1
CPU: (8) x64 Apple M2
Memory: 18.66 MB / 24.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.9.0 - ~/.asdf/installs/nodejs/18.9.0/bin/node
npm: 8.19.1 - ~/.asdf/plugins/nodejs/shims/npm
Browsers:
Brave Browser: 105.1.43.89
Chrome: 105.0.5195.125
Firefox: 103.0
Safari: 15.6.1
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.80
@sveltejs/kit: next => 1.0.0-next.503
svelte: ^3.44.0 => 3.50.1
vite: ^3.1.0 => 3.1.3
Severity
blocking all usage of SvelteKit
Additional Information
I’ve attempting a pretty exhaustive search but cannot find any bugs related to this on Vite or JSDOM and since it works with Node and Vite alone, I’m assuming this is a Kit bug
Issue Analytics
- State:
- Created a year ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
npm not installing jsdom in Windows - Stack Overflow
1 Answer 1 · 5 · @Dbugger To be fair, it works fine on linux/Mac because they generally have Python and a C++...
Read more >JSDOM: How to Get Started - Testim.io
As it turns out, installing JSDOM is very simple. It's intended to be run using NodeJS, so as you'd expect, there is a...
Read more >Setup - Testing Library
Install Vitest and jsdom · Add the following to your package. · You'll need to compile the Svelte components before using them in...
Read more >jest-environment-jsdom-fourteen - npm package - Snyk
Learn more about jest-environment-jsdom-fourteen: package health score, ... package using npm install --save-dev jest-environment-jsdom-fourteen or yarn add ...
Read more >Failing to install MDB-React - Material Design for Bootstrap
json and run npm i . If you still have problem please tell me about it, then I will forward it for our...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

FYI someone having the same issue as you #7045 already did https://github.com/vitejs/vite/issues/10255
Ah, good to know. I’ll submit an issue to Vite, thanks 🙏