question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: `/bin/sh: [filepath]: Permission denied`

See original GitHub issue

Description

An error of type /bin/sh: [filepath]: Permission denied happens when executing lint-staged from the root folder on files located in a subfolder.

I have a root folder with two subfolders. Each subfolder has the linting and formatting packages and configurations. The root folder has Husky and lint-staged.

    .
    β”œβ”€β”€ backend
    β”‚    β”œβ”€β”€ (config files for backend folder)
    β”‚    β”œβ”€β”€ node_modules (includes ESLint and Prettier)
    β”‚    β”œβ”€β”€ package-lock.json
    β”‚    └── package.json
    β”œβ”€β”€ frontend
    β”‚    β”œβ”€β”€ (config files for frontend folder)
    β”‚    β”œβ”€β”€ node_modules (includes ESLint and Prettier)
    β”‚    β”œβ”€β”€ package-lock.json
    β”‚    └── package.json
    β”œβ”€β”€ node_modules (includes Husky and lint-staged)
    β”œβ”€β”€ package-lock.json
    └── package.json

In the root folder package.json I have the following scripts:

"scripts": {
    "lint": "concurrently \"cd backend && npm run lint\" \"cd frontend && npm run lint\"",
    "format": "concurrently \"cd backend && npm run format\" \"cd frontend && npm run format\""
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "(backend|frontend)/**/*.{js,jsx,ts,tsx}": ["npm run lint"],
    "(backend|frontend)/**/*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql}": ["npm run format"]
  },

Running npm run lint or npm run format in the terminal works correctly, but they fail when running with lint staged.

I tried to solve it by following the process for multi package repos without Lerna, but no luck.

Debug Logs

expand to view
husky > pre-commit (node v13.12.0)
  lint-staged:bin Running `lint-staged@10.1.3` +0ms
  lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  debug: true,
  maxArgLength: 131072,
  stash: true,
  quiet: false,
  relative: false,
  shell: false
} +1ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/Users/lllobera/Documents/lewis/plants-almanac/package.json`:
  lint-staged {
  lint-staged   '(backend|frontend)/**/*.{js,jsx,ts,tsx}': [ 'npm run lint' ],
  lint-staged   '(backend|frontend)/**/*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql}': [ 'npm run format' ]
  lint-staged } +10ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '(backend|frontend)/**/*.{js,jsx,ts,tsx}': [
    'npm run lint'
  ],
  '(backend|frontend)/**/*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql}': [
    'npm run format'
  ]
}
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +2ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/lllobera/Documents/lewis/plants-almanac` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `/Users/lllobera/Documents/lewis/plants-almanac` +11ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/lllobera/Documents/lewis/plants-almanac/.git` +0ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +11ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'frontend/package.json' ] +20ms
  lint-staged:chunkFiles Resolved an argument string length of 68 characters from 1 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: '(backend|frontend)/**/*.{js,jsx,ts,tsx}',
  lint-staged:gen-tasks   commands: [ 'npm run lint' ],
  lint-staged:gen-tasks   fileList: []
  lint-staged:gen-tasks } +3ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: '(backend|frontend)/**/*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql}',
  lint-staged:gen-tasks   commands: [ 'npm run format' ],
  lint-staged:gen-tasks   fileList: [
  lint-staged:gen-tasks     '/Users/lllobera/Documents/lewis/plants-almanac/frontend/package.json'
  lint-staged:gen-tasks   ]
  lint-staged:gen-tasks } +1ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'npm run lint' ] +0ms
  lint-staged:task cmd: npm +0ms
  lint-staged:task args: [ 'run', 'lint' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'npm run format' ] +1ms
  lint-staged:task cmd: npm +0ms
  lint-staged:task args: [ 'run', 'format' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
Preparing... [started]
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Getting partially staged files... +0ms
  lint-staged:git Running git command [ 'status', '--porcelain' ] +18ms
  lint-staged:git Found partially staged files: [] +14ms
  lint-staged:git Getting deleted files... +0ms
  lint-staged:git Running git command [ 'ls-files', '--deleted' ] +14ms
  lint-staged:git Found deleted files: [] +9ms
  lint-staged:git Backing up merge state... +0ms
  lint-staged:file Reading file `/Users/lllobera/Documents/lewis/plants-almanac/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/Users/lllobera/Documents/lewis/plants-almanac/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/Users/lllobera/Documents/lewis/plants-almanac/.git/MERGE_MSG` +1ms
  lint-staged:file File `/Users/lllobera/Documents/lewis/plants-almanac/.git/MERGE_HEAD` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/lllobera/Documents/lewis/plants-almanac/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/lllobera/Documents/lewis/plants-almanac/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:git Done backing up merge state! +1ms
  lint-staged:git Running git command [ 'stash', 'save', 'lint-staged automatic backup' ] +10ms
  lint-staged:git Running git command [ 'stash', 'list' ] +51ms
  lint-staged:git Running git command [ 'stash', 'apply', '--quiet', '--index', 'stash@{0}' ] +20ms
  lint-staged:git Restoring merge state... +132ms
  lint-staged:git Done restoring merge state! +0ms
  lint-staged:git Done backing up original state! +0ms
Preparing... [completed]
Running tasks... [started]
Running tasks for (backend|frontend)/**/*.{js,jsx,ts,tsx} [started]
Running tasks for (backend|frontend)/**/*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql} [started]
Running tasks for (backend|frontend)/**/*.{js,jsx,ts,tsx} [skipped]
β†’ No staged files match (backend|frontend)/**/*.{js,jsx,ts,tsx}
npm run format [started]
npm run format [failed]
β†’ 
Running tasks for (backend|frontend)/**/*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql} [failed]
β†’ 
Running tasks... [failed]
Applying modifications... [started]
Applying modifications... [skipped]
β†’ Skipped because of errors from tasks.
Reverting to original state because of errors... [started]
  lint-staged:git Restoring original state... +2s
  lint-staged:git Running git command [ 'reset', '--hard', 'HEAD' ] +2s
  lint-staged:git Running git command [ 'stash', 'list' ] +21ms
  lint-staged:git Running git command [ 'stash', 'apply', '--quiet', '--index', 'stash@{0}' ] +24ms
  lint-staged:git Restoring merge state... +112ms
  lint-staged:git Done restoring merge state! +0ms
  lint-staged:git Done restoring original state! +0ms
Reverting to original state because of errors... [completed]
Cleaning up... [started]
  lint-staged:git Dropping backup stash... +1ms
  lint-staged:git Running git command [ 'stash', 'list' ] +68ms
  lint-staged:git Running git command [ 'stash', 'drop', '--quiet', 'stash@{0}' ] +26ms
  lint-staged:git Done dropping backup stash! +61ms
Cleaning up... [completed]



βœ– npm found some errors. Please fix them and try committing again.

> plants-almanac@1.0.0 format /Users/lllobera/Documents/lewis/plants-almanac
> concurrently "cd backend && npm run format" "cd frontend && npm run format" "/Users/lllobera/Documents/lewis/plants-almanac/frontend/package.json"

[2] /bin/sh: /Users/lllobera/Documents/lewis/plants-almanac/frontend/package.json: Permission denied
[2] /Users/lllobera/Documents/lewis/plants-almanac/frontend/package.json exited with code 126
[0] 
[0] > @plants-almanac/backend@1.0.0 format /Users/lllobera/Documents/lewis/plants-almanac/backend
[0] > prettier --write --check "{,!(.cache|dist|node_modules)/**/}*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql}"
[0] 
[1] 
[1] > @plants-almanac/frontend@1.0.0 format /Users/lllobera/Documents/lewis/plants-almanac/frontend
[1] > prettier --write --check "{,!(.cache|dist|node_modules)/**/}*.{js,jsx,ts,tsx,html,css,json,md,yaml,yml,graphql}" "!src/graphql/types/**"
[1] 
[0] Checking formatting...
[1] Checking formatting...
[0] All matched files use Prettier code style!
[0] cd backend && npm run format exited with code 0
[1] src/index.html
[1] Code style issues fixed in the above file(s).
[1] cd frontend && npm run format exited with code 0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! plants-almanac@1.0.0 format: `concurrently "cd backend && npm run format" "cd frontend && npm run format" "/Users/lllobera/Documents/lewis/plants-almanac/frontend/package.json"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the plants-almanac@1.0.0 format script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/lllobera/.npm/_logs/2020-04-13T11_20_10_178Z-debug.log
husky > pre-commit hook failed (add --no-verify to bypass)

Environment

  • OS: macOS Catalina 10.15.4
  • Node.js: v13.12.0
  • lint-staged: 10.1.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

3reactions
nirvparekhcommented, May 5, 2020

I found the issue mate. It’s because of concurrently. when concurrently runs one script for the file, that file gets locked and another script can’t be run with lint-staged. I replaced "lint": "concurrently \"cd backend && npm run lint\" \"cd frontend && npm run lint\"", with "backend-lint": "npm run lint-backend-fix --prefix backend",

and add lint-backend-fix script in backend/package.json "lint-backend-fix": "npm run lint && npm run format"

and do the similar with frontend change lint-staged with only two scripts, like backend-lint and frontend-fix

1reaction
nirvparekhcommented, May 5, 2020

adding --shell did not worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Permission denied when running sh file - Ask Ubuntu
The permissions don't have the execute bit set, so bash won't execute the script. You can set the bit and execute the script:...
Read more >
How to Fix Shell Script Permission Denied Error in Linux
The shell script permission denied error occurs when the shell script you're trying to run doesn't have the permissions to execute.
Read more >
How to solve the bash: permission denied error? - STechies
The error usually occurs when the script you are trying to execute does not have the necessary permissions. Modifying the permissions of the...
Read more >
How do I fix shell script permission denied in Linux?
This article has provided you a step-by-step procedure for fixing the shell script β€œpermission denied” execution error.
Read more >
Bash permission denied Explanation and Solution
The Bash permission denied error indicates you are trying to execute a file which you do not have permission to run. To fix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found