Redwood: Running `yarn lint` fails if `yarn build` not run first

Created on 11 Apr 2020  ·  9Comments  ·  Source: redwoodjs/redwood

... unless you run yarn build first!

That's a bit counterintuitive to me, I'd expect yarn lint to work as a "standalone" command.
Is that because of the way the project is configured in packages?

Repro:

  • Get a fresh clone of the repo
  • Run yarn install
  • Run yarn lint
  • Error from ESLint:
Oops! Something went wrong! :(

ESLint: 6.8.0.

ESLint couldn't find the plugin "@redwoodjs/eslint-plugin-redwood".

(The package "@redwoodjs/eslint-plugin-redwood" was not found when loaded as a Node module from the directory "/Users/olance/Dev/redwood".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

    npm install @redwoodjs/eslint-plugin-redwood@latest --save-dev

The plugin "@redwoodjs/eslint-plugin-redwood" was referenced from the config file in "package.json » @redwoodjs/eslint-config".

If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.

The plugin was correctly installed though.
After running yarn build, then things started working properly.

I quickly talked to some people on ESLint's Gitter room, here's what they said in the end:

Jordan Harband @ljharb 18:29
however, it seems the real issue is that @redwoodjs/eslint-config is broken - it should have @redwoodjs/eslint-plugin-redwood listed as a peer dep, and you do have to install it as a dev dep yourself, manually.

i'd file an issue on that eslint config to make it a proper peer dep
shared configs must list every plugin they use as a peer dep, it's a limitation of the way shared configs work.
which is, 10 of them, it looks like. so you have to add all 10 as dev deps to your project
look at the airbnb config to see how it's done properly

@peterp I think I heard you like configuring stuff? 😄

bu2-confirmed

Most helpful comment

Thanks @peterp for the research; I can try implementing your idea, I'll let you know :)

All 9 comments

It’s due to the way we use our own config. And, yes, Peter and I have discussed needing to re-structure. Would welcome a PR!

Also heads up, there’s an additional issue (known) with an eslint plugin + VS Code that I’m running into on the Windows fix side of things. See this monster issue

Ah, well, I left the Windows world a long time ago... not missing it 😬

I’m not sure I’ll be able to figure out what’s going on, I don’t have much experience configuring stuff like this, but I can give it a try.

I think I have it. BUT, important and related —> the seems to be a bug in "prettier": "^2.0.4”. We’re currently a v2.02, so no need to update for now.

@olance I believe the issue is here:

https://github.com/redwoodjs/redwood/blob/a6f6b619206b80e5f6074bcd2f0f37cb610a9124/packages/eslint-config/index.js#L23, and here: https://github.com/redwoodjs/redwood/blob/a6f6b619206b80e5f6074bcd2f0f37cb610a9124/packages/eslint-config/index.js#L46

The library that we're referencing ./pacakges/eslint-plugin-redwood is not built, and it's not actually required by the monorepo.

@redwoodjs/eslint-config': Cannot find module '/Users/peterp/Personal/redwoodjs/redwood/node_modules/@redwoodjs/eslint-plugin-redwood/dist/index.js'. Please verify that the package.json has a valid "main" entry

A simple fix might be to have two configurations:

  1. for the redwoodjs framework monorepo
  2. for redwoodjs projects (which includes the eslint-plugin-redwood)

A quick fix would be to dynamically require @redwoodjs/eslint-plugin-redwood to see if it's available, and to only include it in the configuration if it is.

@olance Let me know if you want to give it a go, otherwise I'll probably be able to fix this this week.

Thanks @peterp for the research; I can try implementing your idea, I'll let you know :)

@peterp haven't had the chance to look at this just yet; let me know if you want to take it over, I'll still try to handle it during the week if you can't.

@olance I had a flash of inspiration this morning and fixed this.

Ah! I was gonna get started on it this morning 🙃
Thanks then!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CR1AT0RS picture CR1AT0RS  ·  4Comments

thedavidprice picture thedavidprice  ·  3Comments

cannikin picture cannikin  ·  3Comments

jtoar picture jtoar  ·  4Comments

tmeasday picture tmeasday  ·  4Comments