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

Building with transpilePackages and runtime config on Windows machine produces Windows-only require paths #55697

Closed
1 task done
longzheng opened this issue Sep 21, 2023 · 3 comments
Assignees
Labels
bug Issue was opened via the bug report template. locked SWC Related to minification/transpilation in Next.js.

Comments

@longzheng
Copy link
Contributor

longzheng commented Sep 21, 2023

Link to the code that reproduces this issue

https://github.com/longzheng/next-transpile-windows-path-repro

To Reproduce

  1. Open repro project in a Windows environment
  2. Install packages npm install
  3. Build next npm run build
  4. Copy .next folder onto a Linux/macOS machine
  5. Run Next server with npx next start
  6. See server error in terminal
% npx next start

  ▲ Next.js 13.5.2
  - Local:        http://localhost:3000

 ✓ Ready in 124ms
Error: Cannot find module 'next/dist\shared\lib\runtime-config.external.js'
Require stack:
- /Users/long/Desktop/test/.next/server/pages/index.js
- /Users/long/Desktop/test/node_modules/next/dist/server/require.js
- /Users/long/Desktop/test/node_modules/next/dist/server/next-server.js
- /Users/long/Desktop/test/node_modules/next/dist/server/next.js
- /Users/long/Desktop/test/node_modules/next/dist/server/lib/start-server.js
- /Users/long/Desktop/test/node_modules/next/dist/cli/next-start.js
- /Users/long/Desktop/test/node_modules/next/dist/lib/commands.js
- /Users/long/Desktop/test/node_modules/next/dist/bin/next
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at /Users/long/Desktop/test/node_modules/next/dist/server/require-hook.js:54:36
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at mod.require (/Users/long/Desktop/test/node_modules/next/dist/server/require-hook.js:64:28)
    at require (node:internal/modules/cjs/helpers:121:18)
    at 290 (/Users/long/Desktop/test/.next/server/pages/index.js:1:1394)
    at t (/Users/long/Desktop/test/.next/server/webpack-runtime.js:1:127)
    at 637 (/Users/long/Desktop/test/.next/server/pages/index.js:1:1285)
    at t (/Users/long/Desktop/test/.next/server/webpack-runtime.js:1:127) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/long/Desktop/test/.next/server/pages/index.js',
    '/Users/long/Desktop/test/node_modules/next/dist/server/require.js',
    '/Users/long/Desktop/test/node_modules/next/dist/server/next-server.js',
    '/Users/long/Desktop/test/node_modules/next/dist/server/next.js',
    '/Users/long/Desktop/test/node_modules/next/dist/server/lib/start-server.js',
    '/Users/long/Desktop/test/node_modules/next/dist/cli/next-start.js',
    '/Users/long/Desktop/test/node_modules/next/dist/lib/commands.js',
    '/Users/long/Desktop/test/node_modules/next/dist/bin/next'
  ]
}

Current vs. Expected behavior

Current behaviour

The issue is specific to the combination of two Next.js features, runtime configuration and transpile packages.

runtime configuration https://nextjs.org/docs/pages/api-reference/next-config-js/runtime-configuration

I need to use runtime configuration on the server-side with getServerSideProps

// src/pages/index.tsx
export const getServerSideProps = async () => {
  const { serverRuntimeConfig, publicRuntimeConfig } = getConfig();

  return { props: {} };
};

transpilePackages https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages

I need to support IE 11 and need to transpile Next.js because otherwise the the client chunks are not ES5 compatible.

// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ['next'],
}
 
module.exports = nextConfig

With the combination of the two, when built from a Windows environment, the build output of the server-side JavaScript file .next\server\pages\index.js contains the following require path with double forward slashes.

{e.exports=require("next/dist\\shared\\lib\\runtime-config.external.js")}

Full file here

When built from a Linux/macOS environment, it's

{e.exports=require("next/dist/shared/lib/runtime-config.external.js")}

Full file here

(AFAIK if I run the macOS build with Unix path in Windows environment is fine, but the reverse is not.)

Expected behaviour

I expect to be able to build from a Windows environment that can be run in a Linux environment.

I expect the output file .next\server\pages\index.js to contain

{e.exports=require("next/dist/shared/lib/runtime-config.external.js")}

Verify canary release

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

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.12.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.5.2-canary.2
      eslint-config-next: 13.5.2
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

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

Not sure, SWC transpilation

Additional context

No response

@longzheng longzheng added the bug Issue was opened via the bug report template. label Sep 21, 2023
@github-actions github-actions bot added the SWC Related to minification/transpilation in Next.js. label Sep 21, 2023
@kdy1
Copy link
Member

kdy1 commented Nov 20, 2023

I think #58517 will fix this, but I need to verify

@kdy1 kdy1 self-assigned this Nov 20, 2023
@kdy1
Copy link
Member

kdy1 commented Jan 23, 2024

Closing as fixed on next@latest

@kdy1 kdy1 closed this as completed Jan 23, 2024
Copy link
Contributor

github-actions bot commented Feb 6, 2024

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 Feb 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants