oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.86k stars 2.56k forks source link

Support Parcel #4142

Open birkskyum opened 11 months ago

birkskyum commented 11 months ago

What version of Bun is running?

0.7.4+78defe7a87226b5b10766e24fae458a62811dab2

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

Make an index.html file:

​<html>
  <head>
    <title>My First Parcel App</title>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

Run bun --bun x parcel index.html

What is the expected behavior?

➜ bun --bun x parcel index.html 
Server running at http://localhost:1234
✨ Built in 2ms

This is the case if --bun flag is removed

What do you see instead?


➜ bun --bun x parcel index.html
[bun] Warning: worker_threads.Worker option "execArgv" is not implemented.
dyld[63445]: missing symbol called
error: "parcel" exited with code 9 (SIGKILL)

Additional information

Related to

birkskyum commented 6 months ago

Now I get:

➜ bun --bun x parcel index.html
3592 |         // $FlowFixMe
3593 |         (0, ($parcel$interopDefault($5VgCY$fs))).statSync = (filename)=>{
3594 |             return this.fs.statSync(filename);
3595 |         };
3596 |         try {
3597 |             m.load(filePath);
                   ^
TypeError: m.load is not a function. (In 'm.load(filePath)', 'm.load' is undefined)
      at load (/private/tmp/parcel@latest--bunx/node_modules/@parcel/package-manager/lib/index.js:3597:13)
      at processTicksAndRejections (:61:77)

17 |   try {
18 |     binding = require('./build/Release/watcher.node');
19 |   } catch (err) {
20 |     try {
21 |       binding = require('./build/Debug/watcher.node');
22 |     } catch (err) {
                                                                                                                                                                                                                                                                                                                                        ^
error: No prebuild or local build of @parcel/watcher found. Tried @parcel/watcher-darwin-arm64. Please ensure it is installed (don't use --no-optional when installing with npm). Otherwise it is possible we don't support your platform yet. If this is the case, please report an issue to https://github.com/parcel-bundler/watcher.
      at /private/tmp/parcel@latest--bunx/node_modules/@parcel/watcher/index.js:22:324
      at anonymous (native:1:1)
      at /private/tmp/parcel@latest--bunx/node_modules/@parcel/fs/lib/index.js:7:5
      at anonymous (native:1:1)
      at /private/tmp/parcel@latest--bunx/node_modules/@parcel/package-manager/lib/index.js:10:5
      at anonymous (native:1:1)
      at /private/tmp/parcel@latest--bunx/node_modules/@parcel/core/lib/worker.js:63:1
      at anonymous (native:1:1)
      at /private/tmp/parcel@latest--bunx/node_modules/@parcel/workers/lib/child.js:108:32
      at childInit (/private/tmp/parcel@latest--bunx/node_modules/@parcel/workers/lib/child.js:107:25)
17 |   try {
18 |     binding = require('./build/Release/watcher.node');
19 |   } catch (err) {
20 |     try {
21 |       binding = require('./build/Debug/watcher.node');
22 |     } catch (err) {
KTamas commented 6 months ago

@birkskyum I might be wrong and can't test it right now, but you may need to add @parcel/watcher to trustedDependencies in your package.json because only the top 500 packages get their postinstall scripts ran automatically and my guess is that it may not be on that list.

birkskyum commented 6 months ago

@KTamas , thank you for the tip - I tried just now but I can't make it work.

chdominguez commented 4 months ago

Any news on this? I cannot seem to make parcel work when installed with bun.

KTamas commented 4 months ago

Yeah I'm still waiting on it as well.

koddr commented 2 months ago

The same problems with Bun v1.1.7 and Parcel bundler v2.12.0:

🙏

jtenner commented 2 months ago

I hit similar trouble using bunx --bun parcel

It just looks like a napi feature hasn't been implemented yet. Perhaps someone might be able to point me in the right direction to get this working?

It's blocking me from using bun at work with parcel.

Edit: I meant to say "point me in the right direction to help contribute to this issue..."

Might be time to learn some zig?

jtenner commented 2 months ago

Also, I wanted to point out that @parcel/watch requires the use of detect-libc.

This wouldn't normally be a problem but...

> await import("detect-libc")
Object [Module] {
  GLIBC: 'glibc',
  MUSL: 'musl',
  default: {
    GLIBC: 'glibc',
    MUSL: 'musl',
    family: [Function: family],
    familySync: [Function: familySync],
    isNonGlibcLinux: [Function: isNonGlibcLinux],
    isNonGlibcLinuxSync: [Function: isNonGlibcLinuxSync],
    version: [Function: version],
    versionSync: [Function: versionSync]
  },
  family: [Function: family],
  familySync: [Function: familySync],
  isNonGlibcLinux: [Function: isNonGlibcLinux],
  isNonGlibcLinuxSync: [Function: isNonGlibcLinuxSync],
  version: [Function: version],
  versionSync: [Function: versionSync]
}

This actually looks fine, and uses a function to find the libc family. However, parcel uses the detect-libc package which doesn't expect family to be a function.

let name = `@parcel/watcher-${process.platform}-${process.arch}`;
if (process.platform === 'linux') {
  const { MUSL, family } = require('detect-libc');
  if (family === MUSL) {
    name += '-musl';
  } else {
    name += '-glibc';
  }
}

As you can see here, family is a function and will never equal MUSL, and thus, we get some issues.

We can solve this problem by calling await import("@parcel/watcher") instead of using import watcher from "@parcel/watcher", and I think this is unintended behavior.