admin管理员组

文章数量:1355529

In my project I'm trying to implement ESLint as part of a build process that is launched from an npm script.

I've got eslint and all of the plugins I need all installed as npm packages and I've got my .eslintrc file all setup. When I then run the mand ...

eslint src

... on a mac, everything works perfectly. I can therefore take that mand and stick it into an npm script and it works just fine.

However, on windows I'm experiencing a problem. When I install the eslint npm package I am unable to use eslint from the mand line. I see that it has installed in the node_modules directory and that it put the executable in the node_modules/.bin directory, but when I run the mand ...

eslint src

... I get an error saying that the eslint mand is not found.

I can get it to work if I install eslint and all of my plugins globally, but this isn't ideal because anyone else who clones my code will need to do that also. It's as if on windows, the mand line does not have a 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 mand directly from the mand line it seems to be able to find the eslint mand and everything works perfectly. However, when I place that same mand into an npm script, the script runs with no output and no error.

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

In my project I'm trying to implement ESLint as part of a build process that is launched from an npm script.

I've got eslint and all of the plugins I need all installed as npm packages and I've got my .eslintrc file all setup. When I then run the mand ...

eslint src

... on a mac, everything works perfectly. I can therefore take that mand and stick it into an npm script and it works just fine.

However, on windows I'm experiencing a problem. When I install the eslint npm package I am unable to use eslint from the mand line. I see that it has installed in the node_modules directory and that it put the executable in the node_modules/.bin directory, but when I run the mand ...

eslint src

... I get an error saying that the eslint mand is not found.

I can get it to work if I install eslint and all of my plugins globally, but this isn't ideal because anyone else who clones my code will need to do that also. It's as if on windows, the mand line does not have a 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 mand directly from the mand line it seems to be able to find the eslint mand and everything works perfectly. However, when I place that same mand into an npm script, the script runs with no output and no error.

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

Share Improve this question edited Feb 15, 2016 at 18:09 John Slegers 47.2k23 gold badges204 silver badges173 bronze badges asked Feb 15, 2016 at 18:03 jdavisjdavis 8,67514 gold badges55 silver badges63 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

If you configure your package.json 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"
  }
}

Now just run

npm install

and after that run

npm test

This is should work across OS.

Note: If you run eslint directly then you need to install the eslint globally with npm install eslint -g mand.

本文标签: javascriptRun ESLint from NPM script on WindowsStack Overflow