본문 바로가기

프로그래밍

NextJS 빌드 오류 EPERM, MODULE_NOT_FOUND

반응형

pnpm + Turborepo + NextJS 조합으로 구성된 프로젝트를 윈도우에서 빌드할 때 아래와 같은 오류가 발생한다.

$ pnpm build
> @rsv/main@0.0.0 build C:\Users\*****\Documents\***********-********-*****\apps\main
> relay-compiler --validate && next build

[INFO] [default] compiling...
[INFO] [default] compiled documents: 1 reader, 1 normalization, 1 operation text
[INFO] Compilation completed.
[INFO] Done.
warn  - You have enabled experimental feature (swcPlugins) in next.config.js.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

info  - Linting and checking validity of types

> Build error occurred
[Error: EPERM: operation not permitted, scandir 'C:\*****\qmams\Documents\***********-********-*****\apps\main\.next\standalone\apps\main\node_modules\fp-ts'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'scandir',
  path: 'C:\\Users\\*****\\Documents\\***********-********-*****\\apps\\main\\.next\\standalone\\apps\\main\\node_modules\\fp-ts'
}
info  - Creating an optimized production build . ELIFECYCLE  Command failed with exit code 1.

위에서는 fp-ts 라이브러리의 경로에 접근하지 못 해서 발생한 것으로 나오지만, 꼭 fp-ts 라이브러리가 아니더라도 저 오류는 발생한다.

이와 관련하여 유사한 사례를 찾았다.

https://github.com/vercel/next.js/discussions/40482

 

Standalone output in pnpm monorepo has invalid symlinks in node_modules · vercel/next.js · Discussion #40482

I'm using next 12.3.0 with output: 'standalone' and pnpm. The node_modules directory in standalone/ contains invalid symlinks, presumably because it's copying the symlinks from the project into the...

github.com

NextJS에서 standalone 옵션을 활성화한 경우 pnpm에서 symlink를 올바르게 생성하지 못 하는 것 같다. 다만, outputFileTracingRoot: path.join(__dirname, '../../')과 같이 빌드 결과물을 생성할 때 외부의 node_modules를 참조할 수 있도록 설정해주면 해결된다는 의견도 있었다. 

https://nextjs.org/docs/advanced-features/output-file-tracing#caveats

 

next.config.js Options: output | Next.js

Using Pages Router Features available in /pages

nextjs.org

하지만 내 경우에서는 이 방법으로 해결되지 않았고, 어자피 Amplify에서 Vercel로 넘어간 지금 standalone 옵션도 불필요하여 이를 비활성화해서 문제를 해결했다.

반응형