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

Big bundle size due to jsdom canvas #26973

Closed
xxRockOnxx opened this issue Apr 26, 2024 · 1 comment
Closed

Big bundle size due to jsdom canvas #26973

xxRockOnxx opened this issue Apr 26, 2024 · 1 comment

Comments

@xxRockOnxx
Copy link

xxRockOnxx commented Apr 26, 2024

Environment

Nuxt project info: 5:24:41 am


  • Operating System: Linux
  • Node Version: v20.9.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: bun@1.0.35
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Reproduction: https://codesandbox.io/p/devbox/nuxt-jsdom-canvas-4wgflf
Repo: https://github.com/xxRockOnxx/nuxt-issue

Step 1: install metascraper and metascraper-image packages
Step 2: use it somewhere in a nuxt project. in the reproduction provided, i made a "link-preview" endpoint.
Step 3: build

Describe the bug

I use the packages metascraper and metascraper-image to create a "link preview" api endpoint.

Somewhere in its dependency chain is jsdom which includes canvas as its peer dep.

For some reason, suddenly, I now get giant build output.

I checked using du -h .output/server | sort -h for the biggest file/folder, I saw the following:

17M     .output/server/node_modules/sharp
18M     .output/server/node_modules/re2
18M     .output/server/node_modules/re2/build
18M     .output/server/node_modules/re2/build/Release
180M    .output/server/node_modules/canvas
180M    .output/server/node_modules/canvas/build
180M    .output/server/node_modules/canvas/build/Release
232M    .output/server/node_modules
235M    .output/server/

as opposed to the previous:

17M    ./node_modules/sharp
42M    ./node_modules
44M    .

For some reason it happens specifically on my machine only.

I tried building on a server and github action environment and on codesandbox and they all build as expected like on the "previous" i.e no canvas in .output/server/node_modules.

I'm not sure what change caused this because I don't have any AFAIK.

Doesn't seem to be code issue though cause it work on other environment.

On the other hand, upon checking jsdom's README, I think it shouldn't have the package installed or even bundled unless you have it in your own project's dependencies.

To make this work, you need to include canvas as a dependency in your project, as a peer of jsdom.
From: https://github.com/jsdom/jsdom?tab=readme-ov-file#canvas-support

I'm lost here. Any clues?

Additional context

No response

Logs

No response

@xxRockOnxx
Copy link
Author

xxRockOnxx commented Apr 26, 2024

It's not nuxt related but rather to bun. Specifically on versions after 1.0.16.

Downgrading to 1.0.16 fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant