Running ESLint from NPM script on Windows

In my project, I'm trying to implement ESLint as part of the build process that starts with an npm script.

I have eslint and all the plugins I need, all installed as npm packages, and I have the whole .eslintrc file. When I ran the command ...

eslint src

... on a Mac, everything works fine. So I can take this command and paste it into an npm script, and it works fine.

However, on Windows I have a problem. When I install the eslint npm package, I cannot use eslint from the command line. I see that he installed node_modules in the directory and placed the executable in the node_modules / directory. Bin, but when I ran the command ...

eslint src

... I get an error that the eslint command was not found.

I can make it work if I install eslint and all my plugins globally, but this is not ideal, because someone who clones my code also needs to do this. As if in the windows on the command line there is no path mapped to node_modules /. Bin.

I tried to solve this problem with this little trick:

PATH=$(npm bin):$PATH eslint src

When I run this command directly from the command line, it seems to be able to find the eslint command, and everything works fine. However, when I put the same command in an npm script, the script runs without output and without errors.

Any direction on how to get this job would be awesome. Thanks.

+4
source share
1 answer

If you configure package.jsonin this way

{
  "name": "test",
  "version": "0.1.1",
  "description": "Validate files with ESLint",
  "scripts": {
    "test": "eslint src"
  },
  "devDependencies": {
    "eslint": "^2.0.0",
    "eslint-config-ideal": "^0.1.0"
  }
}

npm install

npm test

.

. eslint , eslint npm install eslint -g.

0

Source: https://habr.com/ru/post/1628886/


All Articles