next.js: operation not permitted
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: 16.15.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.3.2-canary.0
eslint-config-next: 12.3.1
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When I run the build I have this error
> Build error occurred
[Error: EPERM: operation not permitted, scandir 'C:\Users\axell\Documents\Development\pikas-template\apps\app\.next\standalone\apps\app\node_modules\next'] {
errno: -4048,
code: 'EPERM',
syscall: 'scandir',
path: 'C:\\Users\\axell\\Documents\\Development\\pikas-template\\apps\\app\\.next\\standalone\\apps\\app\\node_modules\\next'
}
And in my next.config.js I have this
require('dotenv-flow').config({ path: '../..' });
const withPWA = require('next-pwa');
const withPlugins = require('next-compose-plugins');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const { join } = require('path');
const withTM = require('next-transpile-modules')([]);
const plugins = [withTM, withBundleAnalyzer, withPWA];
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
swcMinify: true,
reactStrictMode: true,
output: 'standalone',
experimental: {
outputFileTracingRoot: join(__dirname, '../../'),
},
i18n: {
locales: ['en', 'fr'],
defaultLocale: 'en',
},
pwa: {
disable: process.env.NODE_ENV === 'development',
dest: 'public',
},
};
module.exports = withPlugins(plugins, nextConfig);
I found these issues that talk about it too: #36645 #1537
Expected Behavior
I just want to build my app
Link to reproduction
https://github.com/Achaak/pikas-template
To Reproduce
Use this command
pnpm i
pnpm generate
pnpm build:packages
cd apps/app
pnpm build <-- The bug appears here
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 18
- Comments: 38 (2 by maintainers)
I encounter the same issue with this setup:
We use standalone output in combination with outputFileTracingRoot for monorepo usage.
If I run
pnpm buildwith normal privileges I get ascandirerror:errno: -4048, code: 'EPERM', syscall: 'scandir',Same command with admin privileges gives me themkdirerror:errno: -4048, code: 'EPERM', syscall: 'mkdir',12.1.7-canary.48produces the same error, so I think it’s always been thereThis is my minimal reproduction example, it’s basically just 3 steps (powershell):
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 likefs.symlinkis not supported ideally at Windows (at least at mine).I fixed it by enabling Windows Developer Mode
I have the same problem with the following setup:
For now, deleting .next folder for almost every build is the solution.
Jumping on the “same issue” train. To workaround this issue set
outputFileTracing: falsein next config. Also, for me, it seems that this issue is not happening on different windows machine with same project code. It could be something related to windows configurationSeems I have managed to find the solution (for me at least). I have prisma database as a shared package in monorepo. The root cause was having
output = "../src/generated/client"which generated prisma client outside of “node_modules” directory. For some reason, nextjs compiler did not like that. I had to specify the output directory tooutput = "../node_modules/.prisma/client"to solve this (you can just remove output option entirely if you have single prisma schema in whole project). The rest was just adjust paths/aliases intsconfig.jsonfiles.For people with same issue, if above does not work, you can try one of following:
outputFileTracing: falsein your next config file. This option, however, will be removed in NextJS 15What’s even more strange is that it’s failing with different directories every time, but always in my user directory.
What could anything in the build possibly be doing in my user directory??? My code is in a completely separate drive.
If @AshleyJackson is right, this means the failure is related to trace files. Isn’t that data you guys phone home with for metrics/etc?
After watching my outgoing traffic, it’s definitely happening when the build phones home to telemetry.nextjs.org.
… Are you guys phoning home data from my user directory???
Having the same problem on windows with pnpm during build. output: “standalone” is not enabled. Windows Developer Mode does not fix the issue.
I can confirm this exact problem with Windows + pnpm. .next/standalone/node_modules includes dependencies in the .pnpm folder instead of the root node_modules folder, leading to
Error: EPERM: operation not permitted, stat 'C:\GitHub\project\.next\standalone\node_modules\next'It works fine with npm as dependencies are in root node_modules
Unsure if this stackoverflow issue is related, then it would mean this is an old issue https://stackoverflow.com/questions/70895922/pnpm-linking-with-standalone-nextjs-build
After several tests with colleagues, the problem would be on windows.
And yes when I remove
output: "standalone"ansoutputFileTracingRootits work but I need itIf your work laptop doesn’t allow enabling developer mode but you still have extended rights, run the build script from an elevated terminal, i.e. run Terminal as an administrator:
I can confirm that this was resolved for me when I turned on developer mode in Windows 11.
for me running the “pnpm run build” in admin mode fix it
Seeing this seemingly at random today.
It also sometimes complains about the path `‘C:\Users\sgcol\Application Data’.
No idea how to even begin with this.
I have just tried it in Linux and it works perfectly. So is Windows + pnpm specific. Turbotrace on Windows does not fix the issue either. And building the standalone folder on Linux, which works, and moving it to Windows and running it still causes the error.