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

elkjs official example works with node but not with bun #15737

Open
tylerlong opened this issue Dec 13, 2024 · 0 comments
Open

elkjs official example works with node but not with bun #15737

tylerlong opened this issue Dec 13, 2024 · 0 comments
Labels
bug Something isn't working confirmed bug We can reproduce this issue Worker uses the web or node worker api

Comments

@tylerlong
Copy link

tylerlong commented Dec 13, 2024

What version of Bun is running?

1.1.38

What platform is your computer?

Darwin 23.6.0 x86_64 i386

What steps can reproduce the bug?

bun add elkjs

Create index.js and copy the sample code from https://github.com/kieler/elkjs?tab=readme-ov-file#example:

const ELK = require('elkjs')
const elk = new ELK()

const graph = {
  id: "root",
  layoutOptions: { 'elk.algorithm': 'layered' },
  children: [
    { id: "n1", width: 30, height: 30 },
    { id: "n2", width: 30, height: 30 },
    { id: "n3", width: 30, height: 30 }
  ],
  edges: [
    { id: "e1", sources: [ "n1" ], targets: [ "n2" ] },
    { id: "e2", sources: [ "n1" ], targets: [ "n3" ] }
  ]
}

elk.layout(graph)
   .then(console.log)
   .catch(console.error)

Run it:

bun src/index.js

What is the expected behavior?

It should work without errors.

What do you see instead?

48 |     if (!optionsClone.workerFactory) {
49 |       var _require = require('./elk-worker.min.js'),
50 |           _Worker = _require.Worker;
51 | 
52 |       optionsClone.workerFactory = function (url) {
53 |         return new _Worker(url);
                    ^
TypeError: undefined is not a constructor (evaluating 'new _Worker(url)')
      at /Users/tyler.liu/src/ts/bun-elkjs-demo/node_modules/elkjs/lib/main.js:53:16
      at ELK (/Users/tyler.liu/src/ts/bun-elkjs-demo/node_modules/elkjs/lib/elk-api.js:51:18)
      at new ELKNode (/Users/tyler.liu/src/ts/bun-elkjs-demo/node_modules/elkjs/lib/main.js:57:99)
      at /Users/tyler.liu/src/ts/bun-elkjs-demo/src/index.js:2:13

Additional information

node src/index.js works

@tylerlong tylerlong added bug Something isn't working needs triage labels Dec 13, 2024
@RiskyMH RiskyMH added confirmed bug We can reproduce this issue Worker uses the web or node worker api labels Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue Worker uses the web or node worker api
Projects
None yet
Development

No branches or pull requests

3 participants