opennextjs-cloudflare: Error when building

Hi, thank you for working on this.

I can’t build my app. This is my wrangler.toml:

name = "project"
main = ".worker-next/index.mjs"

compatibility_date = "2024-08-29"
compatibility_flags = ["nodejs_compat_v2"]

assets = { directory = ".worker-next/assets", binding = "ASSETS" }

This is what I get after running the command "build:worker": "cloudflare" (the project is built and I get to see the summary of the routes in the terminal)

○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand

⚙️ Copying files...

# copyPackageTemplateFiles
⚙️ Bundling the worker file...

# patchWranglerDeps
node:fs:448
    return binding.readFileUtf8(path, stringToFlags(options.flag));
                   ^

Error: ENOENT: no such file or directory, open 
'project/apps/web/.worker-next/.next/standalone/apps/web/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js'

Node.js v22.0.0

As expected, there is no file under that directory image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 20 (6 by maintainers)

Most upvoted comments

@seivad @jsmestad @VojGin

In my case this was caused by an old version of esbuild being installed in our monorepo. Adding

    "esbuild": "0.24.2",

To the Next.js package package.json fixed it

The fix is on its way! 😄

@blakeembrey thanks so much! with that I could reproduce the issue! 😄

I’ve also found the solution, I’ve got to work on something unrelated for a bit, I’ll open a PR with the fix later today 🙂👍

I get the same error as above after converting a project from next-on-pages to opennext, is there any solution?

✘ [ERROR] Invalid alias name: "next/dist/compiled/ws"

✘ [ERROR] Invalid alias name: "next/dist/compiled/edge-runtime"

/Users/mick/code/dashboard/node_modules/.pnpm/esbuild@0.15.18/node_modules/esbuild/lib/main.js:1575
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 2 errors:
error: Invalid alias name: "next/dist/compiled/ws"
error: Invalid alias name: "next/dist/compiled/edge-runtime"

@dario-piotrowicz just to let you know that the build is working on my side using yarn. Thanks for the fix

Thank you a lot, next time I will add a repro for sure!

@dario-piotrowicz I have just tested with 0.0.0-acc0c5e and I get this error now:

updateWebpackChunksFile

  • chunk 135.js
  • chunk 236.js ✘ [ERROR] Invalid alias name: “next/dist/compiled/ws”

✘ [ERROR] Invalid alias name: “next/dist/compiled/edge-runtime”

/{local-path-removed}/node_modules/esbuild/lib/main.js:1575 let error = new Error(${text}${summary}); ^

Error: Build failed with 2 errors: error: Invalid alias name: “next/dist/compiled/ws” error: Invalid alias name: “next/dist/compiled/edge-runtime” at failureErrorWithLog (/Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:1575:15) at /Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:1033:28 at runOnEndCallbacks (/Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:1447:61) at buildResponseToResult (/Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:1031:7) at /Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:1143:14 at responseCallbacks. (/Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:680:9) at handleIncomingPacket (/Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:735:9) at Socket.readFromStdout (/Users/sorenhansen/Code/vivens-io/node_modules/esbuild/lib/main.js:656:7) at Socket.emit (node:events:519:28) at addChunk (node:internal/streams/readable:559:12) { errors: [ { detail: undefined, id: ‘’, location: null, notes: [], pluginName: ‘’, text: ‘Invalid alias name: “next/dist/compiled/ws”’ }, { detail: undefined, id: ‘’, location: null, notes: [], pluginName: ‘’, text: ‘Invalid alias name: “next/dist/compiled/edge-runtime”’ } ], warnings: [] } My scripts looks like this:

“scripts”: { “dev”: “next dev”, “build”: “next build”, “start”: “next start”, “lint”: “next lint”, “deploy”: “cloudflare && wrangler deploy”, “preview”: “cloudflare && wrangler dev”, “cf-typegen”: “wrangler types --env-interface CloudflareEnv env.d.ts” }, And my dependencies looks like this:

“devDependencies”: { “@cloudflare/workers-types”: “^4.20240925.0”, “@opennextjs/cloudflare”: “0.0.0-acc0c5e”, “@types/node”: “20.10.5”, “@types/react”: “18.2.45”, “@types/react-dom”: “18.2.18”, “tailwindcss”: “3.3.5”, “tailwindcss-animate”: “1.0.7”, “eslint”: “8.54.0”, “eslint-config-next”: “14.0.3”, “@cloudflare/next-on-pages”: “1.13.2”, “elysia”: “1.1.8”, “wrangler”: “^3.79.0” } UPDATE: It’s working after I removed the @cloudflare/next-on-pages package.

I’m getting the same error even with the @cloudflare/next-on-pages package removed.

⚙️ Copying files...

# copyPrerenderedRoutes
# copyPackageTemplateFiles
⚙️ Bundling the worker file...

# patchWranglerDeps
# updateWebpackChunksFile
 - chunk 100.js
 - chunk 14.js
 - chunk 148.js
 - chunk 150.js
 - chunk 157.js
 - chunk 20.js
 - chunk 252.js
 - chunk 266.js
 - chunk 291.js
 - chunk 296.js
 - chunk 307.js
 - chunk 397.js
 - chunk 475.js
 - chunk 57.js
 - chunk 605.js
 - chunk 654.js
 - chunk 723.js
 - chunk 727.js
 - chunk 737.js
 - chunk 829.js
 - chunk 91.js
 - chunk 946.js
✘ [ERROR] Invalid alias name: "next/dist/compiled/ws"

✘ [ERROR] Invalid alias name: "next/dist/compiled/edge-runtime"

/Users/username/folder/project/node_modules/esbuild/lib/main.js:1575
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 2 errors:
error: Invalid alias name: "next/dist/compiled/ws"
error: Invalid alias name: "next/dist/compiled/edge-runtime"
    at failureErrorWithLog (/Users/username/folder/project/node_modules/esbuild/lib/main.js:1575:15)
    at /Users/username/folder/project/node_modules/esbuild/lib/main.js:1033:28
    at runOnEndCallbacks (/Users/username/folder/project/node_modules/esbuild/lib/main.js:1447:61)
    at buildResponseToResult (/Users/username/folder/project/node_modules/esbuild/lib/main.js:1031:7)
    at /Users/username/folder/project/node_modules/esbuild/lib/main.js:1143:14
    at responseCallbacks.<computed> (/Users/username/folder/project/node_modules/esbuild/lib/main.js:680:9)
    at handleIncomingPacket (/Users/username/folder/project/node_modules/esbuild/lib/main.js:735:9)
    at Socket.readFromStdout (/Users/username/folder/project/node_modules/esbuild/lib/main.js:656:7)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: null,
      notes: [],
      pluginName: '',
      text: 'Invalid alias name: "next/dist/compiled/ws"'
    },
    {
      detail: undefined,
      id: '',
      location: null,
      notes: [],
      pluginName: '',
      text: 'Invalid alias name: "next/dist/compiled/edge-runtime"'
    }
  ],
  warnings: []
}

Node.js v20.17.0
error Command failed with exit code 1.

I’m on next@14.2.16 and @opennextjs/cloudflare@0.2.1

@fprl it could be fixed now, if you want please try the latest release 0.0.0-acc0c5e

and let me know if it’s all good now 🙂