MINGW-packages icon indicating copy to clipboard operation
MINGW-packages copied to clipboard

nodejs: Unable to run Next.js apps

Open gnpivo opened this issue 2 years ago • 21 comments

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:

> [email protected] 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:

> [email protected] 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

  • [X] I have verified that my MSYS2 is up-to-date before submitting the report (see https://www.msys2.org/docs/updating/)

Windows Version

MINGW64_NT-10.0-19045

MINGW environments affected

  • [ ] MINGW64
  • [ ] MINGW32
  • [x] UCRT64
  • [ ] CLANG64
  • [ ] CLANG32
  • [ ] CLANGARM64

Are you willing to submit a PR?

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

gnpivo avatar Jul 17 '23 00:07 gnpivo

do you have rust package installed?

raedrizqie avatar Jul 17 '23 04:07 raedrizqie

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.

gnpivo avatar Jul 18 '23 02:07 gnpivo

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

raedrizqie avatar Jul 18 '23 05:07 raedrizqie

that does sound likely.

revelator avatar Jul 19 '23 19:07 revelator

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

gnpivo avatar Jul 19 '23 20:07 gnpivo

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 avatar Jul 19 '23 22:07 revelator

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

revelator avatar Jul 20 '23 12:07 revelator

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

lunacd avatar Feb 11 '24 21:02 lunacd

@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?

lunacd avatar Feb 11 '24 21:02 lunacd

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 avatar Feb 11 '24 21:02 revelator

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.

revelator avatar Feb 11 '24 21:02 revelator

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!

lunacd avatar Feb 12 '24 01:02 lunacd

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.

revelator avatar Feb 12 '24 05:02 revelator

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

raedrizqie avatar Feb 12 '24 05:02 raedrizqie

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.

lunacd avatar Feb 12 '24 13:02 lunacd

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.

revelator avatar Feb 12 '24 13:02 revelator

@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

raedrizqie avatar Feb 15 '24 02:02 raedrizqie

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 avatar Feb 15 '24 05:02 revelator

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

revelator avatar Feb 15 '24 09:02 revelator