next.js: [NEXT-1032] A Node.js API is used (process.turbopack at line: 47) which is not supported in the Edge Runtime.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:43 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T8112
    Binaries:
      Node: 19.7.0
      npm: 9.5.0
      Yarn: 3.5.0
      pnpm: N/A
    Relevant packages:
      next: 13.3.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/TrevorThomp/nextjs-auth-repro

To Reproduce

# Make sure you are on latest Yarn version (>2.0.0).
yarn set version stable

# Install dependencies specified in package.json
yarn install

# Build the application
yarn build

# Build Docker container
yarn docker:build

Describe the Bug

When building the Next application through next build the following output occurs and will fail my builds in GCP: Error

I raised this issue with Nextjs-Auth0 and they directed me back to here https://github.com/auth0/nextjs-auth0/issues/1152

The changes that started throwing this error was in the 13.3.0 release: https://github.com/vercel/next.js/pull/47715 https://github.com/vercel/next.js/commit/d71cbe9116f2a260aee44adfc3832ed7c25e57bb#diff-88cc5222d0ce7e563716eee434a1045d101b0043afd2450d66c9eb1ca4ac5cbb

Expected Behavior

Middleware with auth works as expected.

Which browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

N/A

NEXT-1032

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 33
  • Comments: 16 (3 by maintainers)

Most upvoted comments

I confirm that @Defrosted comment mentioning a PR is fixing this, works fine in “13.3.5-canary.5” to me

I have the same error with next-auth

I think I’m getting something related when I add the next-auth/middleware.

middleware.ts

export { default } from "next-auth/middleware";
export const config = { matcher: ["/admin/:path*", "/api/:path*"] };

Error:

[Error: ENOENT: no such file or directory, open '/app/apps/console/.next/server/edge-chunks/wasm_ef4866ecae192fd87727067cf2c0c0cf9fb8b020.wasm']

Can we disable the edge runtime completely when building a standalone app?

I looks like the edge-chunks directory doesn’t get generated for the standalone build. It is generated at .next/server/edge-chunks, but not at .next/standalone/.next/server/edge-chunks, just like the static directory.

As a workaround, I’ve added the following line to the Dockerfile:

COPY --from=builder --chown=nextjs:nodejs /app/.next/server/edge-chunks ./.next/server/edge-chunks

This handles the edge-chunks directory in the same way as the static Directory in the Docker example. It removes the [Error: ENOENT: no such file or directory, open '/app/apps/console/.next/server/edge-chunks/wasm_ef4866ecae192fd87727067cf2c0c0cf9fb8b020.wasm'] runtime error.

I’m guessing that these WASM chunks are related to the image-response stuff, which is meant to be removed during tree shaking. So this is only a workaround, not an actual fix.

I’d love to see an update on this soon.

Sharing this here as well: There was a discussion in #48638 regarding this, and there’s now PR #48723 that attempts to fix this to my understanding.

Same error here using next-intl/middleware.

import createMiddleware from "next-intl/middleware";

export default createMiddleware({
  locales: ["en", "es"],
  defaultLocale: "en",
});

export const config = {
  // Skip all paths that should not be internationalized
  matcher: ["/((?!_next|.*\\..*).*)"],
};

@Defrosted thanks, your workaround was useful to deploy to amplify hosting (using an amplify.yml). Although AppDir is working fine on amplify hosting I wonder about the performance using SST, the cold start of almost 10seconds is a bit annoying. can you tell me if its better on SST?

I think I’m getting something related when I add the next-auth/middleware.

middleware.ts

export { default } from "next-auth/middleware";
export const config = { matcher: ["/admin/:path*", "/api/:path*"] };

Error:

[Error: ENOENT: no such file or directory, open '/app/apps/console/.next/server/edge-chunks/wasm_ef4866ecae192fd87727067cf2c0c0cf9fb8b020.wasm']

Can we disable the edge runtime completely when building a standalone app?

I think I’m getting something related when I add the next-auth/middleware.

middleware.ts

export { default } from "next-auth/middleware";
export const config = { matcher: ["/admin/:path*", "/api/:path*"] };

Error:

[Error: ENOENT: no such file or directory, open '/app/apps/console/.next/server/edge-chunks/wasm_ef4866ecae192fd87727067cf2c0c0cf9fb8b020.wasm']

Can we disable the edge runtime completely when building a standalone app?

I saw that issue as well in GCP logs on builds so it could definitely be related.