msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.25k stars 1.21k forks source link

nodejs: Unable to run Next.js apps #17782

Open gnpivo opened 1 year ago

gnpivo commented 1 year ago

Description / Steps to reproduce the issue

Hi! I am using the mingw-w64-nodejs package for Node.js development. Unfortunately, I can't run the development servers for my Next.js apps. I believe this is a bug because the apps run fine when I use my system's Node.js, but they don't run when I use the MSYS2 version. For both versions, node --version returns v18.16.1.

Here are some steps to recreate the issue I am experiencing:

  1. Create a Next.js app by running this command: npx create-next-app@latest next-app
  2. Press Enter several times to install create-next-app and select the default options
  3. Change into the directory: cd next-app
  4. Run the development server: npm run dev

(You can then run npm uninstall -g create-next-app to uninstall the create-next-app tool.)

Expected behavior

I expected the command npm run dev to run the development server at http://localhost:3000 and produce output similar to that produced by my system's Node.js.

The output should look something like this:

> next-app@0.1.0 dev
> next dev

- ready started server on 0.0.0.0:3000, url: http://localhost:3000
- event compiled client and server successfully in 671 ms (20 modules)
- wait compiling...
- event compiled client and server successfully in 375 ms (20 modules)
- wait compiling /page (client and server)...
- event compiled client and server successfully in 16.7s (486 modules)

Actual behavior

Running npm run dev produces the following output:

> next-app@0.1.0 dev
> next dev

- ready started server on 0.0.0.0:3000, url: http://localhost:3000
thread '<unnamed>' panicked at 'Must load N-API bindings', C:\Users\runneradmin\.cargo\registry\src\
index.crates.io-6f17d22bba15001f\napi-sys-2.2.3\src\functions.rs:7:3
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The server does not run.

Verification

Windows Version

MINGW64_NT-10.0-19045

MINGW environments affected

Are you willing to submit a PR?

I would love to contribute, but I don't know how to fix the issue.

raedrizqie commented 1 year ago

do you have rust package installed?

gnpivo commented 1 year ago

Hi @raedrizqie 😄 I just installed the mingw-w64-rust package and tried running the commands again. Sadly, the same output occurred. 😞 I didn't have the Rust package before.

raedrizqie commented 1 year ago

i think it is because rust binding is not enabled on nodejs

revelator commented 1 year ago

that does sound likely.

gnpivo commented 1 year ago

Would this be an issue on my end, or would it be an issue with the build configuration of the package?

revelator commented 1 year ago

this is a problem with the configuration on this end but you have to understand getting nodejs to build and work with mingw-w64 was quite an undertaking in itself, i just think it sorta went in to the TODO section at some point :). we can try enabling it but there is no guarantee it will work out of the box, a good deal of the nodejs functionality was only recently fixed.

revelator commented 1 year ago

looks like N-API is not an official part of nodejs and might need to be ported first, nodejs itself has no rust bindings.

lunacd commented 7 months ago

I'm looking into this. I'll post updates/ask questions here when there's progress.

lunacd commented 7 months ago

@revelator At first glance, I'm having trouble understanding what would need to be ported in order for this to happen. (I'm comparing with what arch does in the hope to find what we are missing here.) Could you point me somewhere to start looking?

revelator commented 7 months ago

been a while since i looked at anything due to health problems. i dont think the problem is located in our nodejs package itself, it might just be the N-api package that needs some adjustment but i cant find that one in the arch repository so im not sure they ever ported it ?.

revelator commented 7 months ago

ah it was renamed Node-API and it is a part of nodejs now... hmm gotta find out where in it things go wrong then.

lunacd commented 7 months ago

Ah I see. That makes sense! I hope you feel better now! Anyway, please let me know if there's anything I can help with!

revelator commented 7 months ago

sadly no, i broke my back in two places around 15 years ago now, it took them 10 years to figure out it was broken though and in the meantime my nerve connections got all messed up. So i have two metal implants + 8 large screws in my back now :S and there has been some complications. Ill see if i can figure somehing out but it might take a while cause i cant sit for very long anymore.

raedrizqie commented 7 months ago

there is an option enable_rust or simething like that, when building nodejs.. but i dont know if it will make any difference at all.. i will try it later

lunacd commented 7 months ago

sadly no, i broke my back in two places around 15 years ago now, it took them 10 years to figure out it was broken though and in the meantime my nerve connections got all messed up. So i have two metal implants + 8 large screws in my back now :S and there has been some complications. Ill see if i can figure somehing out but it might take a while cause i cant sit for very long anymore.

I'm sorry to hear that. Please, do prioritize your health above all things.

revelator commented 7 months ago

i will though ive not much choice in the matter anyway :) but if i have a good day ill see if i can figure something out.

raedrizqie commented 7 months ago

@gnpivo i think we need to compile nextjs from source.. do you know what are the steps?

if we use npx, it will download the prebuilt node module of swc.win32-x64-msvc.node and try to use it, which is not compatible for mingw env..

so, imo, either you ask them to provide swc.win32-x64-gnu.node or you must compile your own

revelator commented 7 months ago

yeah it would need portage the msvc model will not work with mingw-w64. might not be a big problem creating a port so asking them would make sense.

revelator commented 7 months ago

they could use our patchset for nodejs as a template i believe, that might make things easier for them.

C1Ron commented 4 months ago

I'm having the same behaviour on MSYS2 UCRT64, with npx create-next-app version 14.2.3, node version 21.7.2

thread '<unnamed>' panicked at \.cargo\registry\src\index.crates.io-6f17d22bba15001f\napi-sys-2.3.0\src\functions.rs:7:3:
Must load N-API bindings
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Any news regarding this issue ?

Kreijstal commented 3 months ago

duplicate of #20407 (actually this is the original, but I didn't see it the first time)