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

Support Nx #3786

Open
birkskyum opened this issue Jul 24, 2023 · 17 comments
Open

Support Nx #3786

birkskyum opened this issue Jul 24, 2023 · 17 comments
Labels
node.js Compatibility with Node.js APIs tracking-pkg Issues tracking support for a library or package

Comments

@birkskyum
Copy link
Collaborator

birkskyum commented Jul 24, 2023

Nx - Website - GitHub

What version of Bun is running?

0.7.0

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

  • bun x create-nx-workspace
NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · test2
✔ Which stack do you want to use? · react
✔ What framework would you like to use? · none
✔ Standalone project or integrated monorepo? · standalone
✔ Which bundler would you like to use? · vite
✔ Default stylesheet format · css
✔ Enable distributed caching to make your CI faster · No
  • bun i
  • bun --bun run start

What is the expected behavior?

npm run start

> @test2/source@0.0.0 start
> nx serve


> nx run test2:serve:developmentLocal:   http://localhost:4200/

What do you see instead?

bun --bun run start
$ nx serve
perf_hooks_1.performance.mark is not a function. (In 'perf_hooks_1.performance.mark("init-local")', 'perf_hooks_1.performance.mark' is undefined)
error: script "start" exited with code 1 (SIGHUP)
Debug log
[CPP] ZigString__toExternalValue
[JSC] deref (src/string.zig:95)
[JSC] deref (src/string.zig:95)
[CPP] JSGlobalObject__bunVM
[CPP] JSGlobalObject__bunVM
[CPP] JSValue__isBoolean
[CPP] JSValue__jsType
[CPP] JSGlobalObject__vm
[CPP] JSValue__isCallable
[CPP] JSValue__toZigString
[JSC] ascii (src/bun.js/bindings/bun-simdutf.zig:105)
perf_hooks_1.performance.mark is not a function. (In 'perf_hooks_1.performance.mark("init-local")', 'perf_hooks_1.performance.mark' is undefined)
[CPP] JSGlobalObject__bunVM
[CPP] JSGlobalObject__bunVM
[JSC] dispatchOnExit (src/bun.js/javascript.zig:353)
error: script "start" exited with code 1 (SIGHUP)

Additional information

Nx can be ran with many different frameworks (react, angular etc.), bundlers (vite, webpack etc.), with and without workspaces, but a common denominator is that performance.mark() is used, which isn't implemented in Bun:

@birkskyum birkskyum added the bug Something isn't working label Jul 24, 2023
@robobun robobun added the node.js Compatibility with Node.js APIs label Jul 24, 2023
@Jordan-Hall
Copy link

This would be great. I've got nx plugin releasing soon which works but be nice if we can get this in

@Jordan-Hall
Copy link

@birkskyum Just tried taking these two out and it still appears to be some issue.
image

@Jordan-Hall
Copy link

Just an update:

It's failing on generator function with --bun

isServerAvailable() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return new Promise((resolve) => {
                try {
                    console.info('abv')
                    const socket = (0, net_1.connect)(socket_utils_1.FULL_OS_SOCKET_PATH, () => {
                      console.info('abc')
                      socket.destroy();
                      console.log('jordan');
                      resolve(true);
                    });
                    socket.once('error', (err) => {
                      console.log('jordan 2');
                      console.info('error 2 ', err);
                        resolve(false);
                    });
                }
                catch (err) {
                  console.log('error', err);
                    resolve(false);
                }
            });
        });
    }

image

It will never go pass if (!(yield this.isServerAvailable())) {

@Jordan-Hall
Copy link

Ok, SO main thing is IPC however, I have a custom task runner that will resolve this as long as #3790 is stubbed as NX doesn't actually need to return

@Jordan-Hall
Copy link

@birkskyum Not finished yet but has bun create and run support https://www.npmjs.com/package/@nx-bun/nx

@birkskyum
Copy link
Collaborator Author

birkskyum commented Sep 8, 2023

@Jordan-Hall , IPC was introduced by #4468

@Jordan-Hall
Copy link

Thank you @birkskyum I'll give it a checkout either today or tomorrow to update it. Thays a huge change thank you

@algoflows
Copy link

algoflows commented Sep 15, 2023

This would be great. I've got nx plugin releasing soon which works but be nice if we can get this in

Just seen the website, can't wait. This has been on the most wanted list for about a year.

@Jordan-Hall
Copy link

This would be great. I've got nx plugin releasing soon which works but be nice if we can get this in

Just seen the website, can't wait. This has been on the most wanted list for about a year.

https://github.com/Jordan-Hall/nx-bun-template

Fully working version with NX just in bun and Bun package manager uses patch and fixes event loop.

@birkskyum just event loop issue for nx now #5403 Then this is fully suportted from bun side

@algoflows
Copy link

I think the event loop issue has been resolved over at Bun, does that mean we can just use Bun without the template?

@Jordan-Hall
Copy link

I think the event loop issue has been resolved over at Bun, does that mean we can just use Bun without the template?

That no longer uses fix for event loop. It also has a fix to use Bun as package manager... butbyes you can they issue do not use nx/js:tcs

Still better to use @nx-bun/Bun plugin as it has Bun compiler and run built in

@algoflows
Copy link

okay, so all we need to do is install the nx-bun/Bun plugin?

@Jordan-Hall
Copy link

Yes it has all the generators and executors based on bun.

@nektro
Copy link
Contributor

nektro commented Jan 17, 2024

OP's reproduction is working in Bun 1.0.23 + Nx 17.2.8

image

@birkskyum
Copy link
Collaborator Author

birkskyum commented Jan 17, 2024

@nektro , amazing - i can confirm the dev works!

There is a bit more work to do though as bun --bun run test stalls, and the bun --bun run build throws this:

bun --bun run build
$ nx build

> nx run test2:build:production

vite v5.0.11 building for production...
Could not find 'nx' module in this workspace. 29 |     const onlyStdout = [];
30 |     process.stdout._write = (chunk, encoding, callback) => {
31 |         onlyStdout.push(chunk);
32 |         (0, fs_1.appendFileSync)(stdoutAndStderrLogFileHandle, chunk);
33 |         if (streamOutput) {
34 |             stdoutWrite.apply(process.stdout, [chunk, encoding, callback]);
                 ^
TypeError: undefined is not an object (evaluating 'stdoutWrite.apply')
      at /Users/admin/repos/bun-kitchensink/test2/node_modules/nx/bin/run-executor.js:34:13
      at writeToStdOut (/Users/admin/repos/bun-kitchensink/test2/node_modules/nx/src/utils/output.js:48:9)
      at addNewline (/Users/admin/repos/bun-kitchensink/test2/node_modules/nx/src/utils/output.js:79:9)
      at error (/Users/admin/repos/bun-kitchensink/test2/node_modules/nx/src/utils/output.js:96:9)
      at /Users/admin/repos/bun-kitchensink/test2/node_modules/nx/src/utils/params.js:22:13


 ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target build for project test2 (887ms)
 
    ✖    1/1 failed0/1 succeeded [0 read from cache]
 
error: script "build" exited with code 1

@nektro
Copy link
Contributor

nektro commented Jan 17, 2024

image

working on test next!

@birkskyum
Copy link
Collaborator Author

birkskyum commented Aug 20, 2024

Hmm, with latest canary 1.1.25-canary.40+eb8ed27a4, all commands are hanging agian..

➜ bun --bun run start
$ nx serve

➜ bun --bun run build
$ nx build

@Jarred-Sumner Jarred-Sumner added tracking-pkg Issues tracking support for a library or package and removed bug Something isn't working labels Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node.js Compatibility with Node.js APIs tracking-pkg Issues tracking support for a library or package
Projects
None yet
Development

No branches or pull requests

6 participants