npm run build says react-scripts: Permission denied in CI
sh: 1: react-scripts: Permission deniedShort answer
The shell found node_modules/.bin/react-scripts but may not run it. The usual causes are a node_modules folder that was copied or restored instead of installed, bin links skipped by an earlier install, or a workspace on a filesystem mounted noexec. Reinstall cleanly, rebuild the links, or move the job.
Fix it fast
1Find out which cause you have
Look at the bin link and at how the workspace is mounted.
ls -l node_modules/.bin/react-scripts findmnt -T . -o TARGET,OPTIONS2Match what you see, then jump to its fix
- 1
ls shows a link that is missing, broken or points to a file without execute permissionnode_modules was copied or restored, not installedFix - 2
The build user once ran npm with --no-bin-links or --ignore-scripts, or the folder sits on a share without symlinksAn earlier install skipped bin links or scriptsFix - 3
findmnt shows noexec in the options of the workspace mountThe workspace is on a noexec filesystemFix
- 1
What does the error look like?
sh: 1: react-scripts: Permission deniedsh: react-scripts: Permission denied
Cause 1 of 3
node_modules was copied or restored, not installed
1Check
npm links package executables into node_modules/.bin during install. A folder moved between machines, zipped, or restored from a cache can lose those links or their permissions.
ls -l node_modules/.bin | head2Fix
Let npm build the folder itself. npm ci removes an existing node_modules before it installs from the lockfile.
npm ci3Verify
Run the build.
npm run buildConfirmed by docs.npmjs.com
Cause 2 of 3
An earlier install skipped bin links or scripts
1Check
Bin links are created only when the bin-links setting is true, which is the default. Look for the flags in your CI job and in npm config.
npm config get bin-links
npm config get ignore-scripts2Fix
Remove those flags, then ask npm to rebuild the links.
npm rebuild3Verify
Check the link, then build.
ls -l node_modules/.bin/react-scripts
npm run buildConfirmed by docs.npmjs.com
Cause 3 of 3
The workspace is on a noexec filesystem
1Check
A mount with the noexec option does not permit direct execution of binaries on it, so even a correct link fails.
findmnt -T . -o TARGET,OPTIONS | grep noexec2Fix
Run the build in a directory on a mount without noexec, or have the server admin change the mount options.
mkdir -p /var/build/my-app && cd /var/build/my-app
npm ci && npm run build3Verify
The build starts and prints its normal output.
npm run buildConfirmed by man7.org
How do I stop it coming back?
- Never commit or cache node_modules as the only source; cache the npm download cache and run npm ci.
- Use npm ci in CI jobs so each build starts from a clean tree.
- Keep build workspaces off noexec mounts.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
npm start fails because react-scripts is not found
react-scripts: command not found
npm runs scripts with node_modules/.bin on the PATH.
3 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
npm start stops with Could not find a required file in a React app
Name: index.html
react-scripts checks for two files before the dev server starts: public/index.html and a src/index file.
3 causes, each with a fix