Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tubopack - Edge runtime includes Node APIs and bundles packages that should be aliased/excluded #78162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aymericzip opened this issue Apr 14, 2025 · 2 comments
Labels
locked Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js.

Comments

@aymericzip
Copy link
Contributor

aymericzip commented Apr 14, 2025

Link to the code that reproduces this issue

https://github.com/aymericzip/intlayer-next-15-template

To Reproduce

 git clone [email protected]:aymericzip/intlayer-next-15-template.git
npm install
next start --turbopack

Current vs. Expected behavior

Bug description

When using the edge runtime, Node APIs are implicitly bundled into edge routes (e.g., generateMetadata or middleware) even though they should be excluded or aliased. For example, a package (@intlayer/config/built which includes esbuild) should never be bundled in the edge runtime, yet it is.

Error :

npm run dev:turbo

> [email protected] dev:turbo > next dev --turbopack

   ▲ Next.js 15.3.0 (Turbopack)
   - Local:        http://localhost:3000
   - Network:      http://192.168.1.37:3000

 ✓ Starting...
 ⨯ ./node_modules/.pnpm/@[email protected]/node_modules/@esbuild/darwin-arm64/README.md
Unknown module type
This module doesn't have an associated type. Use a known file extension, or register a loader for it.

Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders


 ✓ Compiled middleware in 402ms
 ✓ Ready in 9.5s
 ⨯ Error [TypeError]: Cannot read properties of undefined (reading 'node')
    at [project]/packages/@intlayer/config/dist/esm/loadExternalFile.mjs [middleware-edge] (ecmascript) (packages/@intlayer/config/src/loadExternalFile.ts:2:63)
  1 | import { runInNewContext } from 'vm';
> 2 | import { type BuildOptions, buildSync, type BuildResult } from 'esbuild';
    |                                                               ^
  3 | import { getSandBoxContext } from './getSandboxContext';
  4 | import { ESMxCJSRequire } from './utils/ESMxCJSRequire';
  5 | import { logger } from './logger';
 ⚠ ./packages/@intlayer/config/dist/esm/configFile/buildConfigurationFields.mjs:166:57

esbuild, fs, path etc are imported via the @intlayer/config/built package

As a result, dev and built fail using turbopack because the package references Node APIs not supported in the Edge environment.

Image
  • Current behavior:
    A runtime error is thrown in routes that runs on the Edge runtime.
    This happens despite the package being aliased away via a custom plugin (withIntlayer) or excluded using the serverExternalPackages option in next.config.js.

  • Expected behavior:
    The aliasing or externalization should prevent the package from being bundled into the edge runtime, similar to how it behaves with webpack

Provide environment information

Operating System:
  Platform: macos
  Arch: x64
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  pnpm: 9.14.3
Relevant Packages:
  next: <14.2.28 to 15.3.0,
  react: 18.3.1 
  react-dom: 18.3.1
  typescript: 5.7.2
Next.js Config:
  output: N/A

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

Runtime, Turbopack, Middleware, Metadata

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

next dev (local)
next build (local)

Additional context

Related issue:
aymericzip/intlayer#109

Started since next 14.x.x

Reproducible example repo:
https://github.com/aymericzip/intlayer-next-14-template

@github-actions github-actions bot added Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js. labels Apr 14, 2025
@aymericzip
Copy link
Contributor Author

Fixed using relative path as alias

Commit:
aymericzip/intlayer@dd88655

Copy link
Contributor

github-actions bot commented May 7, 2025

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.

@github-actions github-actions bot added the locked label May 7, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant