cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages

Home Page:https://www.npmjs.com/package/@cloudflare/next-on-pages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[πŸ› Bug]: Unsupported Node.js version! Your version: undefined

richtera opened this issue Β· comments

next-on-pages environment related information

❯ yarn next-on-pages --info

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
CPU: (12) arm64 Apple M2 Max
Memory: 32 GB
Shell: /bin/zsh
Package Manager Used: yarn (4.2.2)

Relevant Packages:
@cloudflare/next-on-pages: 1.11.3
vercel: N/A
next: 14.2.3

Description

For some reason I cannot currently compile an app with next-on-pages. I have lots of apps using this, but for this app, the web sandbox doesn't have process.version defined and therefore it serializes a process.exit() into the code causing it to error out that process.exit is not supported in the edge runtime. I can't quite tell what is triggering the missing process.version, because the node runtime obviously has process.version defined. I made sure to add a webpack config to defined process.version, but that didn't help, because it happens on the sandbox and not during the webpack build.

Reproduction

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

The project is setup to work with asdf or mise and will attempt to use node 20.5.1, so you might need mise install nodejs or asdf install nodejs.

the output should look like this

yarn pages:build
⚑️ @cloudflare/next-on-pages CLI v.1.11.3
⚑️ Detected Package Manager: yarn (4.2.2)
⚑️ Preparing project...
⚑️ Project is ready
⚑️ Building project...
β–²  ➀ YN0000: Β· Yarn 4.2.2
β–²  ➀ YN0000: β”Œ Resolution step
β–²  ➀ YN0085: β”‚ + vercel@npm:34.2.2, @cspotcode/source-map-support@npm:0.8.1, @edge-runtime/format@npm:2.2.1, @edge-runtime/node-utils@npm:2.3.0, and 332 more.
β–²  ➀ YN0000: β”” Completed in 0s 512ms
β–²  ➀ YN0000: β”Œ Fetch step
β–²  ➀ YN0013: β”‚ 317 packages were added to the project (+ 188.65 MiB).
β–²  ➀ YN0000: β”” Completed in 0s 264ms
β–²  ➀ YN0000: β”Œ Link step
β–²  ➀ YN0007: β”‚ esbuild@npm:0.14.47 must be built because it never has been before or the last one failed
β–²  ➀ YN0000: β”” Completed in 0s 818ms
β–²  ➀ YN0000: Β· Done in 1s 631ms
β–²  
β–²  Vercel CLI 34.2.2
β–²  Warning: Detected "engines": { "node": "20.5.1" } in your `package.json` with major.minor.patch, but only major Node.js Version can be selected. Learn More: http://vercel.link/node-version
β–²  Installing dependencies...
β–²  ➀ YN0000: Β· Yarn 4.2.2
β–²  ➀ YN0000: β”Œ Resolution step
β–²  ➀ YN0000: β”” Completed
β–²  ➀ YN0000: β”Œ Post-resolution validation
β–²  ➀ YN0060: β”‚ eslint is listed by your project with version 9.3.0, which doesn't satisfy what eslint-config-next (p90fe7) and other dependencies request (^8.56.0).
β–²  ➀ YN0002: β”‚ Wownar@workspace:. doesn't provide vercel (p38e12), requested by @cloudflare/next-on-pages.
β–²  ➀ YN0002: β”‚ Wownar@workspace:. doesn't provide wrangler (p84dba), requested by @cloudflare/next-on-pages.
β–²  ➀ YN0086: β”‚ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code.
β–²  ➀ YN0000: β”” Completed
β–²  ➀ YN0000: β”Œ Fetch step
β–²  ➀ YN0000: β”” Completed in 0s 252ms
β–²  ➀ YN0000: β”Œ Link step
β–²  ➀ YN0000: β”” Completed
β–²  ➀ YN0000: Β· Done with warnings in 0s 420ms
β–²  Detected Next.js version: 14.2.3
β–²  Running "yarn run build"
β–²  Node.js version: v20.5.1
β–²  β–² Next.js 14.2.3
β–²  - Environments: .env
β–²  
β–²  Creating an optimized production build ...
β–²  βœ“ Compiled successfully
β–²  Linting and checking validity of types ...
β–²  β¨― ESLint: Invalid Options: - Unknown options: useEslintrc, extensions - 'extensions' has been removed.
β–²  Collecting page data ...
β–²  Unsupported Node.js version! Your version: undefined. Required version: >=19.9.0.
β–²  Unsupported Node.js version! Your version: undefined. Required version: >=19.9.0.
β–²  /Users/andy/Development/wownar/node_modules/next/dist/server/web/sandbox/context.js:108
β–²  throw error;
β–²  ^
β–²  
β–²  Error: A Node.js API is used (process.exit) which is not supported in the Edge Runtime.
β–²  Learn more: https://nextjs.org/docs/api-reference/edge-runtime
β–²  at throwUnsupportedAPIError (/Users/andy/Development/wownar/node_modules/next/dist/server/web/sandbox/context.js:105:19)
β–²  at Object.<anonymous> (/Users/andy/Development/wownar/node_modules/next/dist/server/web/sandbox/context.js:123:32)
β–²  at 82437 (/Users/andy/Development/wownar/.next/server/edge-chunks/668.js:1:762)
β–²  at t (/Users/andy/Development/wownar/.next/server/edge-runtime-webpack.js:1:128)
β–²  at 41090 (/Users/andy/Development/wownar/.next/server/app/api/cast/route.js:1:1560)
β–²  at t (/Users/andy/Development/wownar/.next/server/edge-runtime-webpack.js:1:128)
β–²  at 75627 (/Users/andy/Development/wownar/.next/server/app/api/cast/route.js:1:541)
β–²  at t (/Users/andy/Development/wownar/.next/server/edge-runtime-webpack.js:1:128)
β–²  at t (/Users/andy/Development/wownar/.next/server/app/api/cast/route.js:1:1629)
β–²  at /Users/andy/Development/wownar/.next/server/app/api/cast/route.js:1:1654
β–²  Unsupported Node.js version! Your version: undefined. Required version: >=19.9.0.
β–²  
β–²  > Build error occurred
β–²  Error: Failed to collect page data for /api/cast
β–²    at /Users/andy/Development/wownar/node_modules/next/dist/build/utils.js:1268:15
β–²    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
β–²  type: 'Error'
β–²  }
β–²  Error: Command "yarn run build" exited with 1

The repo is a clone of https://github.com/neynarxyz/farcaster-examples/tree/main/wownar with added npm upgrades, a local install of @cloudflare/next-on-pages and the required .tool-versions, .node-version and mise.yaml to make it build everywhere.

Pages Deployment Method

Pages CI (GitHub/GitLab integration)

Pages Deployment ID

No response

Additional Information

I have tried both Pages CI and local builds, but neither work right now.
I can help fix this bug as long as I know where the sandbox is initializing the fake process object containing for example { browser: true }

Would you like to help?

  • Would you like to help fixing this bug?

Seems like a nextjs problem. Adding a bug there.

function createProcessPolyfill() {
    const processPolyfill = {
        env: buildEnvironmentVariablesFrom(),
        version: process.version // ADDING THIS
    };
    const overridenValue = {};
    for (const key of Object.keys(process)){
        if (key === "env" || key === "version") continue; // AND key === "version"
        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;
}
``` makes the compile go through further.

Thanks a bunch for the issue @richtera πŸ™‚πŸ‘

As I can see from the logs you shared, and as you mentioned, that this seems to be an issue with Next.js itself and not next-on-pages (the error happens during the Next.js build before next-on-pages does anything), so if it's ok by you I'm going to close this issue as I believe that the right place for this is the Next.js repository (where you already created an issue and opened a PR to fix it! πŸ’ͺ πŸš€ 🀩 ).

If you disagree please let me know and feel free to reopen the issue.