vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.02k stars 26.7k forks source link

zeromq works standalone but not when used within Next.js: "No native build was found for ..." #61844

Closed eulersson closed 7 months ago

eulersson commented 7 months ago

Link to the code that reproduces this issue

https://github.com/eulersson/zeromq.js-next.js-errors

To Reproduce

Manually

Basically create a next app npx create-next-app@latest with all the defaults, install zeromq npm install zeromq@6.0.0-beta.19, import it anywhere in app/page.tsx (e.g. import { Push } from "zeromq"; and const sock = new Push(); anywhere in your file), start the development server npm run dev and visit http://localhost:3000.

Reproducible Container

  1. Clone this repository git@github.com:eulersson/zeromq.js-node.js-errors.git
  2. Build the Debian Docker container provided docker build -t zeromq-nextjs
  3. Run the Next.js development server container docker run --rm -it -p 3000:3000 nextjs-zeromq
  4. Visit http://localhost:3000 on your host browser.

Current vs. Expected behavior

error-screenshot

Observations

If I change this line in the node-gyp-build/index.js to dir = '/absolute/path/to/node_modules/zeromq' then it works! It seems that it needs to be in .next/server... Because it looks for the prebuilds in there. I read and tried (unsuccessfully) the feature to includes files to the tracing process that happens where only the relevant files are moved to .next/server so a standalone server can use that reduced selection of dependencies.

Error Log

Full error log attached: full-error-log.txt

Error log except:

root@3ae29fabb9db:/app# npm run dev

> my-app@0.1.0 dev
> next dev

   ▲ Next.js 14.1.0
   - Local:        http://localhost:3000

 ✓ Ready in 2.3s
 ○ Compiling /not-found ...

warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
warn - https://tailwindcss.com/docs/content-configuration
 ✓ Compiled / in 7.3s (471 modules)
Error: No native build was found for platform=linux arch=x64 runtime=node abi=115 uv=1 libc=glibc node=20.11.0 webpack=true
    loaded from: /app/.next/server

    at load.path (webpack-internal:///(rsc)/./node_modules/@aminya/node-gyp-build/index.js:50:11)
    at load (webpack-internal:///(rsc)/./node_modules/@aminya/node-gyp-build/index.js:20:32)
    at eval (webpack-internal:///(rsc)/./node_modules/zeromq/lib/native.js:6:123)
    at (rsc)/./node_modules/zeromq/lib/native.js (/app/.next/server/vendor-chunks/zeromq.js:40:1)
    at __webpack_require__ (/app/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///(rsc)/./node_modules/zeromq/lib/index.js:7:16)
    at (rsc)/./node_modules/zeromq/lib/index.js (/app/.next/server/vendor-chunks/zeromq.js:30:1)
    at __webpack_require__ (/app/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///(rsc)/./app/page.tsx:7:64)
    at (rsc)/./app/page.tsx (/app/.next/server/app/page.js:217:1)
    at Function.__webpack_require__ (/app/.next/server/webpack-runtime.js:33:42)
    at async eq (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:402260)
    at async tr (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:405987)
    at async tn (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:406537)
    at async tn (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:406668)
    at async tu (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:36:2057)
    at async /app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:36:2564 {
  digest: '3408682970'
}
 ⨯ node_modules/@aminya/node-gyp-build/index.js (60:8) @ load.path
 ⨯ Error: No native build was found for platform=linux arch=x64 runtime=node abi=115 uv=1 libc=glibc node=20.11.0 webpack=true
    loaded from: /app/.next/server

    at __webpack_require__ (/app/.next/server/webpack-runtime.js:33:42)
    at __webpack_require__ (/app/.next/server/webpack-runtime.js:33:42)
    at eval (./app/page.tsx:7:64)
    at (rsc)/./app/page.tsx (/app/.next/server/app/page.js:217:1)
    at Function.__webpack_require__ (/app/.next/server/webpack-runtime.js:33:42)
    at async Promise.all (index 0)
null
[...] (see full error log)

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1-Alpine SMP PREEMPT_DYNAMIC Mon, 05 Jun 2023 09:39:09 +0000
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

I cannot have this simple hello world app running on macOS 14.1.1 either...

NEXT-2485

eulersson commented 7 months ago

Will be fixed if all goes will with this issue resolution https://github.com/vercel/nft/issues/391 with PR https://github.com/vercel/nft/pull/392.

eulersson commented 7 months ago

@vercel/nft version 0.26.4 fixes it.

github-actions[bot] commented 6 months ago

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.