vercel / next.js

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

Unsupported Node.js version! Your version: undefined #66180

Open richtera opened 3 months ago

richtera commented 3 months ago

Link to the code that reproduces this issue

https://github.com/richtera/wownar

To Reproduce

git checkout https://github.com/richtera/wownar
cd wownar
yarn
yarn build

The same thing happens with yarn pages:build which is why I posted an issue there first https://github.com/cloudflare/next-on-pages/issues/791

Current vs. Expected behavior

Currently is errors out because the polyfill for process doesn't have version on it. Rewriting the polyfill as

function createProcessPolyfill() {
    const processPolyfill = {
        env: buildEnvironmentVariablesFrom(),
        version: process.version
    };
    const overridenValue = {};
    for (const key of Object.keys(process)){
        if (key === "env" || key === "version") continue;
        Object.defineProperty(processPolyfill, key, {
            get () {
                if (overridenValue[key] !== undefined) {
                    return overridenValue[key];
                }
                if (typeof process[key] === "function") {
                    return ()=>throwUnsupportedAPIError(`process.${key}`);
                }
                return undefined;
            },
            set (value) {
                overridenValue[key] = value;
            },
            enumerable: false
        });
    }
    return processPolyfill;
}

https://github.com/vercel/next.js/blob/2966b85bccf0d2593e04dd3aa0ac474f53715d2f/packages/next/src/server/web/sandbox/context.ts#L130

makes builds pass. I can't tell when this started or anything about that however. This is just a fresh nextjs project I got from elsewhere https://github.com/neynarxyz/farcaster-examples/tree/main/wownar and the bug is inside of next.js

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 20.5.1
  npm: 9.8.0
  Yarn: 4.2.2
  pnpm: 8.8.0
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

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

Not sure, Developer Experience

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

next build (local)

Additional context

Since the code in canary is still missing "version" I am not sure if makes sense to attempt a canary build.

richtera commented 3 months ago

Once you modify the polyfill it gets further but I have problems with my /404 routing so I will push a fix for that.

richtera commented 3 months ago

Added a branch "patched" into my repo which patches nextjs and fixes the routing issues to deploy the whole thing on cloudflare to make sure all the pieces work together.

michaelcohen716 commented 1 month ago

hey @richtera - have you had any luck with the next team on this? facing a similar issue

richtera commented 1 month ago

No they didn't agree it was their issue. You're welcome to use my patch. Maybe if you ping them separately?