vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.75k stars 26.95k forks source link

Windows with pnpm and output standalone not work properly #50803

Closed sergiohgz closed 6 months ago

sergiohgz commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Enterprise
    Binaries:
      Node: 16.18.1
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.4.5-canary.5
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A

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

Operating System (Windows, MacOS, Linux), Package manager (npm, pnpm, Yarn), Standalone mode (output: "standalone")

Link to the code that reproduces this issue or a replay of the bug

https://github.com/sergiohgz/nextjs-docker-pnpm-windows-issue

To Reproduce

Using Windows:

  1. Clone reproduction repo or create a repo using pnpm and nextjs-docker example and install latest/canary version of Next.js
  2. Install dependencies using pnpm install
  3. Ensure output: 'standalone' is set up in next.config.js
  4. Execute pnpm build and wait to fail

Describe the Bug

When using Windows and output standalone with pnpm, project doesn't build due to symlinks errors. Tried using several configurations, like node-linker=hoisted, and issue persist.

The final output when script clones necessary dependencies to standalone folder shows something similar to:

> Build error occurred
- warn Failed to copy traced files for C:\Users\sherrerag\Documents\workspace\nextjs-docker\.next\server\pages\_app.js [Error: EPERM: operation not permitted, symlink 'C:\Users\sherrerag\Documents\workspace\nextjs-docker\node_modules\.pnpm\next@13.4.5-canary.5_react-dom@18.2.0_react@18.2.0\node_modules\next' -> 'C:\Users\sherrerag\Documents\workspace\nextjs-docker\.next\standalone\node_modules\next'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'symlink',
  path: 'C:\\Users\\sherrerag\\Documents\\workspace\\nextjs-docker\\node_modules\\.pnpm\\next@13.4.5-canary.5_react-dom@18.2.0_react@18.2.0\\node_modules\\next',
  dest: 'C:\\Users\\sherrerag\\Documents\\workspace\\nextjs-docker\\.next\\standalone\\node_modules\\next'
}
- warn Failed to copy traced files for C:\Users\sherrerag\Documents\workspace\nextjs-docker\.next\server\pages\_error.js [Error: EPERM: operation not permitted, symlink 'C:\Users\sherrerag\Documents\workspace\nextjs-docker\node_modules\.pnpm\@swc+helpers@0.5.1\node_modules\@swc\helpers' -> 'C:\Users\sherrerag\Documents\workspace\nextjs-docker\.next\standalone\node_modules\.pnpm\next@13.4.5-canary.5_react-dom@18.2.0_react@18.2.0\node_modules\@swc\helpers'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'symlink',
  path: 'C:\\Users\\sherrerag\\Documents\\workspace\\nextjs-docker\\node_modules\\.pnpm\\@swc+helpers@0.5.1\\node_modules\\@swc\\helpers',
  dest: 'C:\\Users\\sherrerag\\Documents\\workspace\\nextjs-docker\\.next\\standalone\\node_modules\\.pnpm\\next@13.4.5-canary.5_react-dom@18.2.0_react@18.2.0\\node_modules\\@swc\\helpers'
}

> Build error occurred
[Error: EPERM: operation not permitted, symlink 'C:\Users\sherrerag\Documents\workspa-jsx' -> 'C:\Users\sherrerag\Documents\workspace\nextjs-docker\.next\standalone\node_modules\.pnpm\next@13.4.5-canary.5_react-dom@18.2.0_react@18.2.0\node_modules\styled-jsx'] {
  syscall: 'symlink',
  path: 'C:\\Users\\sherrerag\\Documents\\workspace\\nextjs-docker\\node_modules\\.pnpm\\styled-jsx@5.1.1_react@18.2.0\\node_modules\\styled-jsx',
  dest: 'C:\\Users\\sherrerag\\Documents\\workspace\\nextjs-docker\\.next\\standalone}

Expected Behavior

Using Windows, Next.js project should compile when using output standalone like in other systems.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

jonasjaa commented 1 year ago

I get the same issue when running tests such as playwright on a self-hosted runner in Github actions..

Enalmada commented 1 year ago

For those also hitting this issue on windows, I was able to work around this by running in an administrator powershell.

next info

    Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.16.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.14-canary.1
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A
Arctomachine commented 1 year ago

Same issue with npm and yarn too. Tested at 20-canary.0

AhmedBaset commented 1 year ago

Any solution for this?

bangonkali commented 1 year ago

I have the same issue. It is probably related to somewhere here: https://github.com/vercel/next.js/pull/35535, https://github.com/vercel/next.js/discussions/40482 & https://github.com/vercel/next.js/discussions/52244. Context is from next-config-standalone.

It is probably a good idea to consider multiple fallback procedures for Windows builds. My configuration works without issue on Docker based environment node:18-alpine on CI/CD Platform and in local docker build on Windows. It seems that the issue is related to symlink.

I'm no expert in this area but it seems pnpm has multiple methods described on .npmrc configuration package-import-method=auto|hardlink|copy|clone|clone-or-copy. Maybe an implementation that is something similar to that for tracing output standalone linking?

I'm using turbo@1.10.16-canary.1 pnpm@8.9.0 along with:

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 18.18.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 13.5.5-canary.15
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.9.5
Next.js Config:
  output: standalone
alaindeurveilher commented 11 months ago

Hello, will there be someone working on this issue please? I am also facing the issue on Windows with standalone output. Thank you.

huozhi commented 11 months ago

There were few windows specific fixes in v14, does anyone still have that issue after upgrading to v14?

alaindeurveilher commented 11 months ago

Yes, I am currently with 14.0.2 experiencing this. As a workaround for the moment, I need to use node-linker in hoisted mode instead of isolated, which is sad.

AhmedBaset commented 9 months ago

In my case, this issue occurs on output: "standalone". https://github.com/vercel/next.js/blob/4125069840ca98981f0e7796f55265af04f3e903/packages/next/src/build/utils.ts#L1957 It seems like fs.symlink is not supported ideally at Windows (at least at mine).

I fixed it by enabling Windows Developer Mode

DiskCrasher commented 8 months ago

Running into a similar but slightly different issue. I have my Yarn PnP project saved on a file server mapped to the Z: drive. When I run yarn build I get:

⚠ Failed to copy traced files for Z:\Documents\Programming\redis-app-nextjs\.next\server\pages\_app.js [Error: ENOENT: no such file or directory, mkdir 'Z:\Documents\C:'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: 'Z:\\Documents\\C:'
}
001123 commented 7 months ago

In my case, this issue occurs on output: "standalone".

https://github.com/vercel/next.js/blob/4125069840ca98981f0e7796f55265af04f3e903/packages/next/src/build/utils.ts#L1957

It seems like fs.symlink is not supported ideally at Windows (at least at mine). I fixed it by enabling Windows Developer Mode

It work for me too, thanks man ✋

sergiohgz commented 6 months ago

In my case, this issue occurs on output: "standalone".

https://github.com/vercel/next.js/blob/4125069840ca98981f0e7796f55265af04f3e903/packages/next/src/build/utils.ts#L1957

It seems like fs.symlink is not supported ideally at Windows (at least at mine). I fixed it by enabling Windows Developer Mode

Tried from my side this and the problem is resolved. Thank you so much @AhmedBaset !!

github-actions[bot] commented 5 months ago

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.