Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gts does not work in a yarn workspaces monorepo #490

Closed
darkbasic opened this issue Apr 21, 2020 · 9 comments
Closed

gts does not work in a yarn workspaces monorepo #490

darkbasic opened this issue Apr 21, 2020 · 9 comments

Comments

@darkbasic
Copy link

$ yarn run clean
yarn run v1.22.4
$ gts clean
Error: /home/niko/WebstormProjects/beach/beach-monorepo/packages/server/tsconfig.json Not Found
    at getBase (/home/niko/WebstormProjects/beach/beach-monorepo/node_modules/gts/build/src/util.js:66:15)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ yarn run check
yarn run v1.22.4
$ gts check "src/**/*.ts"
internal/modules/cjs/loader.js:955
  throw err;
  ^

Error: Cannot find module '/home/niko/WebstormProjects/beach/beach-monorepo/packages/server/node_modules/eslint/bin/eslint'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
    at Function.Module._load (internal/modules/cjs/loader.js:835:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

In order to make it work you have to nohoist both gts and eslint.

@realpha
Copy link

realpha commented Apr 22, 2020

Experienced the same issue. The nohoist option is a quick fix, but given eslint package size, it hurts. Espeacially since we want to use it in ALL WORKSPACES.
It would be great if gts could use the 'next' available eslint binary, althought I can't anticipate the potential downsides of this...

@darkbasic
Copy link
Author

To easily reproduce the issue I created a repro: https://github.com/darkbasic/apollo-monorepo
Remove gts and eslint from the nohoist to trigger the error: https://github.com/darkbasic/apollo-monorepo/blob/cf8517c262a18b7d363d96f2dd31a410b1666d45/package.json#L10

@devshorts
Copy link

devshorts commented Jan 14, 2021

This is definitely a regression. GTS v 1 was able to find hoisted tslint, but now GTS 3 can't find hoisted eslint. Can we get this fixed as this impedes anyone with a monorepo from properly migrating from tslint to eslint linting? Nohoist is not a recommendation and should really be avoided for both file size and the fact that yarn explicitly says its a bad idea

@JustinBeckwith
Copy link
Collaborator

Greetings folks - we don't actively use Yarn, and I don't have any immediate plans to do work here. However - I would happily accept a PR!

richardbarrell-calvium added a commit to calvium/gts that referenced this issue Jul 16, 2021
Rationale:
- `npm install`, `yarn` and `lerna` all fill out `node_modules/.bin`
- But `node_modules/eslint` isn't necessarily present.
- This should fix issue google#490.
richardbarrell-calvium added a commit to calvium/gts that referenced this issue Jul 16, 2021
Rationale:
- `npm install`, `yarn` and `lerna` all put an eslint bianry in `node_modules/.bin`, even though they may not create `node_modules/eslint` (if it happens to be hoisted into a parent directory).
- This should fix issue google#490.
richardbarrell-calvium added a commit to calvium/gts that referenced this issue Jul 19, 2021
Rationale:
- npm and Yarn both put (a directory containing) the eslint binary on PATH during "npm run foo", so take advantage of that to invoke eslint in a way that is compatible with Yarn workspaces.
- (Node that `node_modules/eslint/...` may not exist, because the module may have been installed in another `node_modules` further up the filesystem tree. Yarn does ensure that the binary gets symlinked into `node_modules/.bin`.)
- This should fix issue google#490.
@livgust
Copy link

livgust commented Apr 29, 2022

This is failing for me as well with npm's workspace functionality, FYI. Thanks for the nohoist suggestion, looking forward to a more robust fix!

@devshorts
Copy link

I found it easier to just rip out GTS completely and use eslint/prettier normally. Then everything works just fine in a monorepo and you have more control of your lint rules. if you want to start with the gts rules you totally can just by grabbing their eslint configurations. Going the nohoist route is a big hammer to a lint problem since nohoist means you're going to duplicate all your node modules

@livgust
Copy link

livgust commented Apr 29, 2022

I actually ended up doing this since npm workspaces doesn't have nohoist as an option, so I was stuck. I just removed the gts-specific npm scripts from package.json and kept the configs since those were working without issue. I have a top-level lint that is working with gts so I just make sure my CI/CD pipeline uses that.

richardbarrell-calvium added a commit to calvium/gts that referenced this issue Jul 25, 2022
Rationale:
- npm and Yarn both put (a directory containing) the eslint binary on PATH during "npm run foo", so take advantage of that to invoke eslint in a way that is compatible with Yarn workspaces.
- (Node that `node_modules/eslint/...` may not exist, because the module may have been installed in another `node_modules` further up the filesystem tree. Yarn does ensure that the binary gets symlinked into `node_modules/.bin`.)
- This should fix issue google#490.
@Maytha8
Copy link

Maytha8 commented Jan 23, 2023

A workaround:

yarn config set nodeLinker node-modules

or add this to .yarnrc.yml

nodeLinker: node-modules

then run:

yarn

Sourced from https://stackoverflow.com/a/60043794

barbarah added a commit to colonial-heritage/dataset-browser that referenced this issue Apr 12, 2023
I noticed that gts fix and gts link wasn't working in the npm workspaces. This is related to the issues:

gts monorepo does not work with npm ? google/gts#752
gts does not work in a yarn workspaces monorepo google/gts#490
The last issue is with yarn but has more discussion. One solution was using nohoist. This is not a default option with npm. So I tried with the following package https://github.com/zgriesinger/noist. But this did not fix the errors. The last solution mentioned was only linting from the root level; this works.

I have also subscribed to the issue [feature] support npm workspaces. There may be a better solution in the future.
danielbankhead pushed a commit that referenced this issue Sep 29, 2023
Rationale:
- npm and Yarn both put (a directory containing) the eslint binary on PATH during "npm run foo", so take advantage of that to invoke eslint in a way that is compatible with Yarn workspaces.
- (Node that `node_modules/eslint/...` may not exist, because the module may have been installed in another `node_modules` further up the filesystem tree. Yarn does ensure that the binary gets symlinked into `node_modules/.bin`.)
- This should fix issue #490.
@ittaibaratz
Copy link

For me gts 5.2.0 with #654 fixes the problem. I think this bug can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants