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

Unable to find module canvas #4259

Closed
nooblyf opened this issue Aug 22, 2023 · 9 comments
Closed

Unable to find module canvas #4259

nooblyf opened this issue Aug 22, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@nooblyf
Copy link

nooblyf commented Aug 22, 2023

What version of Bun is running?

0.7.3

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

In a new project
bun init
bun add konva canvas

// ./src/index.ts
import Konva from "konva";

const stage = new Konva.Stage({
  container: "container",
  width: 500,
  height: 500,
});

var layer = new Konva.Layer();
stage.add(layer);

var box = new Konva.Rect({
  x: 50,
  y: 50,
  width: 100,
  height: 50,
  fill: "#00D2FF",
  stroke: "black",
  strokeWidth: 4,
  draggable: true,
});
layer.add(box);

console.log(stage.toDataURL());

I'm thinking this has to do something with canvas not being installed properly?

What is the expected behavior?

Being able to log the dataURI succesfully

What do you see instead?

error: Cannot find module "../build/Release/canvas.node" from "/Users/nooblyf/github.com/projects/hello-bun/node_modules/canvas/lib/bindings.js"

Additional information

No response

@nooblyf nooblyf added the bug Something isn't working label Aug 22, 2023
@birkskyum
Copy link
Collaborator

birkskyum commented Aug 22, 2023

With node/npm I often see something like this as well, and in that case the solution is to rebuild the library. This section of MapLibre GL JS contribution guidelines explains it well:

Apple silicon If you have one of the newer arm64 machines, you might find that canvas.node or webgl.node can't be found for your architecture. In that case go to node_modules/canvas and node_modules/gl and run:

npm install --build-from-source

So if you go to node_modules/canvas and run bun install --build-from-source, then canvas can be found. I do though with your reproduction then receive: (bun version 0.8.0+52802a4c556d7498d75d00e4fe4e45633f4283e8)

bun run index.ts               
dyld[67546]: missing symbol called
zsh: killed     bun run index.ts
Debug log
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[JSC] toJS (src/string.zig:501)
[JSC] Bun__fetchBuiltinModule (src/bun.js/module_loader.zig:1860)
[JSC] Bun__runVirtualModule (src/bun.js/module_loader.zig:1978)
[CPP] JSGlobalObject__bunVM
[CPP] JSGlobalObject__bunVM
[JSC] Bun__transpileFile (src/bun.js/module_loader.zig:1890)
[ModuleLoader] transpileFile: /Users/admin/repos/canvas-test/node_modules/canvas/index.js
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[fs] openat(0, /Users/admin/repos/canvas-test/node_modules/canvas/index.js) = 5
[fs] stat(5) = 2933
[fs] pread(5, 2933) = 2933
[fs] readdir(7, /Users/admin/repos/canvas-test/node_modules/canvas/lib/) = 10
[fs] open(/Users/admin/repos/canvas-test/node_modules/canvas/lib) = fs.IterableDir{ .dir = fs.Dir{ .fd = 7 } }
[SYS] close(7)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] createLatin1 (src/string.zig:328)
[SYS] close(5)
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[JSC] fromJS (src/string.zig:479)
[JSC] fromJS (src/string.zig:479)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[JSC] toJS (src/string.zig:501)
[JSC] Bun__fetchBuiltinModule (src/bun.js/module_loader.zig:1860)
[JSC] Bun__runVirtualModule (src/bun.js/module_loader.zig:1978)
[CPP] JSGlobalObject__bunVM
[CPP] JSGlobalObject__bunVM
[JSC] Bun__transpileFile (src/bun.js/module_loader.zig:1890)
[ModuleLoader] transpileFile: /Users/admin/repos/canvas-test/node_modules/canvas/lib/canvas.js
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[fs] openat(0, /Users/admin/repos/canvas-test/node_modules/canvas/lib/canvas.js) = 5
[fs] stat(5) = 3264
[fs] pread(5, 3264) = 3264
[JSC] createLatin1 (src/string.zig:328)
[SYS] close(5)
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[JSC] fromJS (src/string.zig:479)
[JSC] fromJS (src/string.zig:479)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[JSC] toJS (src/string.zig:501)
[JSC] Bun__fetchBuiltinModule (src/bun.js/module_loader.zig:1860)
[JSC] Bun__runVirtualModule (src/bun.js/module_loader.zig:1978)
[CPP] JSGlobalObject__bunVM
[CPP] JSGlobalObject__bunVM
[JSC] Bun__transpileFile (src/bun.js/module_loader.zig:1890)
[ModuleLoader] transpileFile: /Users/admin/repos/canvas-test/node_modules/canvas/lib/bindings.js
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[fs] openat(0, /Users/admin/repos/canvas-test/node_modules/canvas/lib/bindings.js) = 5
[fs] stat(5) = 280
[fs] pread(5, 280) = 280
[fs] readdir(7, /Users/admin/repos/canvas-test/node_modules/canvas/build/Release/) = 4
[fs] open(/Users/admin/repos/canvas-test/node_modules/canvas/build/) = fs.IterableDir{ .dir = fs.Dir{ .fd = 7 } }
[fs] readdir(7, /Users/admin/repos/canvas-test/node_modules/canvas/build/) = 8
[fs] open(/Users/admin/repos/canvas-test/node_modules/canvas/build/Release) = fs.IterableDir{ .dir = fs.Dir{ .fd = 8 } }
[SYS] close(7)
[SYS] close(8)
[JSC] createLatin1 (src/string.zig:328)
[SYS] close(5)
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[JSC] fromJS (src/string.zig:479)
[JSC] fromJS (src/string.zig:479)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] ref (src/string.zig:107)
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[JSC] toJS (src/string.zig:501)
dyld[71930]: missing symbol called
zsh: killed     BUN_DEBUG_ALL=1 BUN_JSC_dumpModuleLoadingState=1  --bun run index.ts

@xhyrom
Copy link
Collaborator

xhyrom commented Aug 24, 2023

You can go into node_modules/canvas and then do bun run install to run install script, it should solve this issue

edit: it relies on V8 so it won't work but by 1.0 it should be solved

@nooblyf
Copy link
Author

nooblyf commented Aug 29, 2023

Is this what you're talking about https://bun.sh/docs/runtime/nodejs-apis#node-v8

@xhyrom
Copy link
Collaborator

xhyrom commented Aug 29, 2023

Is this what you're talking about https://bun.sh/docs/runtime/nodejs-apis#node-v8

yes, v8 is engine but bun is running on WebKit so we must do polyfill

@nooblyf
Copy link
Author

nooblyf commented Aug 29, 2023

alright, thanks!

@7f8ddd
Copy link
Contributor

7f8ddd commented Sep 11, 2023

Automattic/node-canvas#2235
or
https://github.com/Automattic/node-canvas/tree/napi for the branch with NAPI

This will fix canvas whenever it gets pushed, which should be pretty soon.

@tonydawhale
Copy link

tonydawhale commented Sep 19, 2023

Looks like with Automattic/node-canvas#2235 merged, I am still encountering the same error.

❯ bun add canvas@Automattic/node-canvas
[0.81ms] ".env.local"
bun add v1.0.0 (822a00c4)

 installed canvas@github:Automattic/node-canvas#16c28ab


 1 packages installed [1.90s]
  "dependencies": {
    "canvas": "Automattic/node-canvas",
    "css": "^3.0.0",
    "elysia": "latest"
  },
❯ bun dev
$ bun run --watch src/index.ts
[0.08ms] ".env.local"


error: Cannot find module "../build/Release/canvas.node" from "[dir]/node_modules/canvas/lib/bindings.js"

Would maybe using an alternative package such as @napi-rs/canvas or sharp work?

EDIT: Using @napi-rs/canvas is a great alternative. Basically the same thing.

@M1FSS
Copy link

M1FSS commented Sep 20, 2023

Cannot find module "../build/Release/canvas.node"

Workaround: cd node_modules/canvas ; npm run install

However, this leads me to #4290

@Electroid
Copy link
Contributor

Closing as a duplicate of #5835

@Electroid Electroid closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants