import-sort
import-sort copied to clipboard
Running as package.json script fails with "npm ERR! code ELIFECYCLE", works fine via npx
Running an npm script as "npm run sort-imports" where the line in package.json is: "sort-imports": "import-sort --list-different src/**/*.js", lists 20 files and returns error:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @xxx/[email protected] sort-imports: import-sort --list-different src/**/*.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @xxx/[email protected] sort-imports 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/zzz/.npm/_logs/2019-11-21T01_27_36_620Z-debug.log
Running "npx import-sort-cli --list-different src/**/*.js" works fine and returns 29 files that need to have imports sorted.
npm --version 6.12.1
npx --version 6.12.1
node --version v12.13.1
"import-sort-cli": "^6.0.0",
I tried a few different things -- it seems what ended up working was using a line like this in the package.json:
"sort-imports": "import-sort --list-different \"src/**/*.js\"",
The error didn't seem to indicate that this would be the problem per se, but the other issue I was having was that it was only getting files that were 2 levels under src, and in one configuration running the cli with npx was giving me an error unless I put the glob in quotes, so I tried it and it seemed to work. Maybe this should be added to the docs (unless I missed it in there...).
I had the same issue. Changing script definition from "sort-imports": "import-sort --write 'src/**/*.{js,jsx}'" to "sort-imports": "import-sort --write \"src/**/*.{js,jsx}\"" fixed it. It looks like an OS-dependent problem.