Skip to content
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

new URL(”...” , import.meta.url) to get the path, but the file contents are unintentionally loaded at build time. #75021

Open
yskszk63 opened this issue Jan 17, 2025 · 1 comment
Labels
Module Resolution Module resolution (CJS / ESM, module resolving).

Comments

@yskszk63
Copy link

Link to the code that reproduces this issue

https://github.com/yskszk63/nextjs-unexpected-js-eval

To Reproduce

  1. npm run build

Current vs. Expected behavior

Current

$ npm run build

> build
> next build

   ▲ Next.js 15.2.0-canary.13

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Error: 🙈
    at Object.<anonymous> (/home/yskszk63/work/nextjs-unexpected-js-eval/node_modules/throw-error-on-load/throw.js:1:7)
    at Module._compile (node:internal/modules/cjs/loader:1566:14)
    at Object..js (node:internal/modules/cjs/loader:1718:10)
    at Module.load (node:internal/modules/cjs/loader:1305:32)
    at Function._load (node:internal/modules/cjs/loader:1119:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Module.<anonymous> (node:internal/modules/cjs/loader:1327:12)
    at mod.require (/home/yskszk63/work/nextjs-unexpected-js-eval/node_modules/next/dist/server/require-hook.js:65:28)
    at require (node:internal/modules/helpers:136:16)
Export encountered an error on /page: /, exiting the build.
 ⨯ Static worker exited with code: 1 and signal: null

Expected behavior

The build completes successfully.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Fri, 10 Jan 2025 00:39:41 +0000
  Available memory (MB): 30844
  Available CPU cores: 16
Binaries:
  Node: 23.4.0
  npm: 11.0.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.2.0-canary.13 // Latest available version is detected (15.2.0-canary.13).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

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

Module Resolution

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

next dev (local), next build (local)

Additional context

I want to get the path of an asset after build, but unintentionally the specified file is loaded.

Removing serverExternalPackages from next.config.ts works as expected.

@github-actions github-actions bot added the Module Resolution Module resolution (CJS / ESM, module resolving). label Jan 17, 2025
@yskszk63
Copy link
Author

The throw-error-on-load module used in the reproduced code was created to reproduce this case.
It simply throws an error when loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module Resolution Module resolution (CJS / ESM, module resolving).
Projects
None yet
Development

No branches or pull requests

1 participant