sheerun / prettier-standard

Formats with Prettier and lints with ESLint+Standard! (✿◠‿◠)
MIT License
868 stars 44 forks source link

[Error] There was trouble creating the ESLint CLIEngine #1

Closed BenoitAverty closed 4 years ago

BenoitAverty commented 7 years ago

Hello !

First of all, thanks for this amazing project, I love it :)

Context : I'm using prettier-standard with husky and lint-staged. Relevant parts of package.json :

{
  "name": "client",
  "version": "1.0.0",
  "private": true,
  "devDependencies": {
    "husky": "^0.13.2",
    "lint-staged": "^3.4.0",
    "prettier-standard": "^1.0.4",
    "react-scripts": "^0.8.4"
  },
  "dependencies": {
    ...
  },
  "scripts": {
   ...
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "gitDir": "../",
    "linters": {
      "client/src/**/*.js": [
        "prettier-standard",
        "git add"
      ]
    }
  },
  "proxy": "http://localhost:8080"
}

I don't know if it's relevant, but my git repository contains two folders : client and server. Server is a Java spring boot application, and client contains the package.json above (hence the 'gitDir' option and the linter pattern)

When I run yarn run precommit, I get the following error :

yarn run v0.20.3
$ lint-staged 
 ❯ Running tasks for client/src/**/*.js
   → failure formatting 1 file with prettier-standard
   ✖ prettier-standard
     → failure formatting 1 file with prettier-standard
     git add
🚫 prettier-standard found some errors. Please fix them and try committing again.
prettier-eslint [ERROR]: There was trouble creating the ESLint CLIEngine. Is "eslintPath: /home/benoit/Documents/YR/ihm-address-control/client/node_modules/prettier-standard/node_modules/eslint" a correct path to the ESLint module?
prettier-standard [ERROR]: There was an error formatting "/home/benoit/Documents/YR/ihm-address-control/client/src/index.js": 
    Error: Cannot find module '/home/benoit/Documents/YR/ihm-address-control/client/node_modules/prettier-standard/node_modules/eslint'
        at Function.Module._resolveFilename (module.js:472:15)
        at Function.Module._load (module.js:420:25)
        at Module.require (module.js:500:17)
        at require (internal/module.js:20:19)
        at getESLintCLIEngine (/home/benoit/Documents/YR/ihm-address-control/client/node_modules/prettier-eslint/dist/index.js:219:20)
        at getConfig (/home/benoit/Documents/YR/ihm-address-control/client/node_modules/prettier-eslint/dist/index.js:187:22)
        at format (/home/benoit/Documents/YR/ihm-address-control/client/node_modules/prettier-eslint/dist/index.js:78:54)
        at MapSubscriber.rxReadFile.map.text [as project] (/home/benoit/Documents/YR/ihm-address-control/client/node_modules/prettier-standard/lib/format-files.js:242:55)
        at MapSubscriber._next (/home/benoit/Documents/YR/ihm-address-control/client/node_modules/rxjs/operator/map.js:77:35)
        at MapSubscriber.Subscriber.next (/home/benoit/Documents/YR/ihm-address-control/client/node_modules/rxjs/Subscriber.js:89:18)
failure formatting 1 file with prettier-standard

I'm guessing the problem commes from prettier-standard because the path it's complaining about is in prettier-standard, but I could be wrong.

The problem is that eslint is included both by prettier-standard and prettier-eslint, so yarn doesn't put it in the prettier-standard node_modules folder. I found a workaround by adding an old version of prettier-eslint in my package.json, so that the current version end up in the folder that causes the error.

Do you know what might be causng this ? I looked in the code a bit, and it seems this line should find the correct path, but it doesn't for some reason.

Is there an option that I can give to prettier-standard to avoid this, or is there a bug ?

Thanks in advance

sheerun commented 7 years ago

Hey,

Thanks for bug-report. First af all prettier-eslint is a part of prettier-standard so you don't need both if you happen to depend on both of them.

For now I'm not able to reproduce this issue. What's the location of package.json? I see you're writing client/src/**/*.js in linters section, but node_modules seems to be in ihm-address-control/client/node_modules. What's your node version? Maybe you could push a repository that reproduces this issue?

BenoitAverty commented 7 years ago

Thanks for the quick reply.

Here is how the repository is :

ihm-address-control # that's the root of my repo
├ integration-tests/ #Contains some javascript code that I don't want touched by prettier-standard
├ server/ # that's java code in there. We don't care
└ client/
    ├ src/ # my source code. This is what I want formatted
    ├ node_modules/
    └ package.json # this is the package.json I've included earlier.

Currently, my package.json contains "prettier-eslint": "4.2.0", but that's only because this is the workaround I've found. Ideally, i'd remove this (like I showed in the package.json included above).

When I put prettier-eslint inside my package.json, I have the following in the repo directory :

With this, everything works fine.

But when I don't put prettier-eslint in my package.json, here's what I have

I think this is normal : Yarn tries to flattent the dependencies inside node_modules when it can, and when I include an older version of prettier-eslint this has the effet of preventing this, which makes eslint end up in prettier-standard node_modules.

But what I don't understand is why the correct path of eslint is not detected : from what I've read of your source code, you are using find-up to find eslint, which should always work (at worst, finding eslint at the topmost level in my project's node_modules). But when eslint is not present in the prettier-standard node_module, it seems to still look for it at the same place (which cause the error i've copied in my first post).

I hope this helps you understand the problem. I'll try to make a repo to reproduce.

sheerun commented 7 years ago

Thanks, I've managed to reproduce the issue, let me see what I can do

sheerun commented 7 years ago

This should be fixed if you update to 1.0.5, thanks!

sheerun commented 7 years ago

@BenoitAverty Do you mind if I add you to the contributors list in the README?

BenoitAverty commented 7 years ago

Awesome, It looks like it works ! Tanks a lot for your very quick fix.

You're welcome to add me to the contributors list of course, and thank you for that also (I just now discovered the awesome contributors spec)

Morantron commented 7 years ago

Oops, this is broken again in 6.0.0, but works in 5.1.0

franleplant commented 6 years ago

Im seeing this same error in 7.x

mserranom commented 6 years ago

Experiencing in 8.0.1

cstuncsik commented 6 years ago

same here as @mserranom, but adding eslint as an explicit dependency solved the problem for me

here is the relevant part of my package.json (originally bootstrapped with create-react-app at stackblitz):


"scripts": {
    "build-css": "node-sass-chokidar src/ -o src/",
    "watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
    "start-js": "react-scripts start",
    "start": "npm-run-all -p watch-css start-js",
    "build": "npm run build-css && react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "lint:js": "prettier-standard 'src/**/*.{js,jsx}'",
    "lint:style": "prettier-stylelint 'src/**/*.scss' --write --quiet",
    "lint": "npm-run-all -p lint:js lint:style",
    "precommit": "lint-staged"
  },
  "dependencies": {
    "autodux": "4.0.0",
    "classnames": "^2.2.6",
    "ramda": "0.25.0",
    "react": "16.5.1",
    "react-dom": "16.5.1",
    "react-redux": "5.0.7",
    "react-redux-lifecycle": "2.2.0",
    "react-scripts": "1.1.5",
    "recompose": "0.30.0",
    "redux": "4.0.0",
    "redux-form": "7.4.2",
    "redux-logger": "3.0.6"
  },
  "devDependencies": {
    "babel-preset-react-app": "^3.1.2",
    "eslint": "^5.6.0",
    "husky": "^0.14.3",
    "lint-staged": "^7.2.2",
    "node-sass-chokidar": "^1.3.3",
    "npm-run-all": "^4.1.3",
    "prettier-standard": "^8.0.1",
    "prettier-stylelint": "^0.4.2",
    "stylelint": "^9.5.0",
    "stylelint-config-standard": "^18.2.0",
    "stylelint-scss": "^3.3.0"
  },
tr1ms commented 4 years ago

I'm experiencing the same issue on version 9.0.1

electriquo commented 4 years ago

@sheerun: would you please confirm whether it happens on your end for version 9.0.1?

sheerun commented 4 years ago

Works for me. Please remove eslint from devDependencies or use the latest version. Otherwise please provide package.json that reproduces this issue and doesn't use legacy version of eslint

tr1ms commented 4 years ago

Here my package.json

  "scripts": {
    "lint": "eslint '**/*.js'",
    "lint:fix": "prettier-eslint '**/*.js' --write"
  },
  "devDependencies": {
    "eslint": "^6.7.2",
    "eslint-config-standard": "^14.1.0",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-node": "^10.0.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-react": "^7.17.0",
    "eslint-plugin-standard": "^4.0.1",
    "prettier-eslint": "^9.0.1",
    "prettier-eslint-cli": "^5.0.0"
  }
sheerun commented 4 years ago

@gsonly You are using prettier-eslint, not prettier-standard this is prettier-standard

tr1ms commented 4 years ago

@sheerun oh my bad but thanks for response anyway