turbo icon indicating copy to clipboard operation
turbo copied to clipboard

ESLint cannot find next/babel when using pnpm

Open ChristianIvicevic opened this issue 1 year ago • 8 comments

What version of Turborepo are you using?

1.4.0

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Mac

Describe the Bug

After checking out the repository and opening the with-pnpm example and running pnpm install I noticed that ESLint is having issues in the editor. It claims that there is no module next/babel and this error is displayed both in WebStorm and VSCode. My gut feeling is that next/babel is usually referenced as a transitive peer dependency which doesn't work well with the strict nature of pnpm.

image

The error appears only when opening the root .eslintrc.js and the index.js in the eslint-config-custom package. Linting generally works and running pnpm lint works as well, it is just really annoying seeing errors when editing either of the files. Opening the basic example or a repository scaffolded with create-turbo and using npm instead of pnpm does not have this particular issue.

Expected Behavior

No ESLint errors in any configuration file.

To Reproduce

Open the with-pnpm example in WebStorm or VSCode with enabled ESLint plugins and install dependencies using pnpm. I could reproduce this with v6.32.25 and v7.7.0 of pnpm both installed with corepack.

ChristianIvicevic avatar Jul 30 '22 05:07 ChristianIvicevic

you can try configuring your eslint plugin to detect your workspaces under vscode settings.

eslint.workingDirectories: [{ "pattern": "apps/*" }]

i'm still trying to find out why this happens with pnpm in the first place or why this resolves it.

shametim avatar Jul 30 '22 17:07 shametim

Even though this proposal can also be applied to WebStorm there is an inherent incompatiblity with pnpm that's not fixed by this. For the time being I applied the pattern I used in the nx-version of my repo with declaring ignorePatterns: ['**/*'] in the eslint-config-custom and then reverting this in the .eslintrc.js within my apps and packages as follows:

module.exports = {
  root: true,
  ignorePatterns: ['!**/*'],
  extends: ['custom'],
};

ChristianIvicevic avatar Jul 30 '22 18:07 ChristianIvicevic

Maybe this patch from Rush, could also improve things: https://www.npmjs.com/package/@rushstack/eslint-patch

weyert avatar Aug 01 '22 05:08 weyert

Sadly I won't be able to test the suggested patch since I completely gave up on pnpm again.

Every few months when I try it out there is still issues with packages not adhering to decent standards and thus being incompatible with pnpm. This time around it was prisma... but that is offtopic and another story.

ChristianIvicevic avatar Aug 01 '22 05:08 ChristianIvicevic

Screen Shot 2022-08-03 at 8 50 31 PM

I get a similar error though I am using yarn :(

brizzbuzz avatar Aug 04 '22 02:08 brizzbuzz

Try using degit to clone down the directory instead of cloning this whole repo. I've added readme instructions in #1884 and I was able to run npm run lint successfully that way and also don't see any issues in VSCode (which is admittedly not WebStorm, but since we've had multiple issues reported about this, I think it is probably a similar config issue)

mehulkar avatar Sep 08 '22 00:09 mehulkar

I still look to be having this issue using VS Code 😬

Adam-Collier avatar Oct 14 '22 18:10 Adam-Collier

This may be the same root cause as #1911 in that next dependency isn't available, rather than an issue related to pnpm 🤔 . Not sure when I'll have time to dig into it, but our examples/ setup needs a bit of love.

mehulkar avatar Oct 14 '22 19:10 mehulkar

Any update on this issue? When I generate the default project using pnpm create turbo@latest (with Next 13), I keep getting the error "cannot find module next/babel". I tried adding the working directories, but this didn't resolve the error.

bryanbarrios avatar Dec 29 '22 04:12 bryanbarrios

found out a hacky way to fix this create a settings file .vscode/settings.json or add it to your global settings.json

  "eslint.workingDirectories": [
    { "pattern": "apps/*/" },
    { "pattern": "packages/*/" }
  ]

Hamziss avatar Jan 19 '23 20:01 Hamziss

@Hamziss Didn't work for me 😞

steida avatar Jan 20 '23 22:01 steida

@Hamziss Installing next in root package.json solves this but it's hacky solution to me and I don't like it. I used it though.

barthicus avatar Jan 20 '23 22:01 barthicus

@ImBIOS has put up a nice approach to address this here: https://github.com/vercel/turbo/pull/3489

tknickman avatar Jan 26 '23 15:01 tknickman

Merged, going to close for now, but please reopen if this issue comes up again!

tknickman avatar Jan 27 '23 03:01 tknickman