Eslint-plugin-import: Support for PnP?

Created on 3 Aug 2019  路  4Comments  路  Source: benmosher/eslint-plugin-import

So I just watched JSConf EU 2019 on YouTube and found out about Yarn Berry, as well as the idea of yarn pnp. So I decided to try it oout on a nothing project and it seems to be working quite well. But I decided to add in my usual suite of testing/linting stuff and your plugin in particular seems to be going haywire. I was wondering if/when you planned on adding support, or if there's a resolver in the works, like eslint-import-resolver-node? Like I said, it's not a priority for me, and I don't think Yarn 2 is releasing any time soon, per se, but I checked the issues and PRs already available and "pnp" didn't show up.

Example output:

.../Projects/kgm-api/src/graphql/gadgetType.js
  1:1  error  Resolve error: unable to load resolver "node"  import/no-unresolved
  1:1  error  Resolve error: unable to load resolver "node"  import/named
  1:1  error  Resolve error: unable to load resolver "node"  import/no-extraneous-dependencies
  1:1  error  Resolve error: unable to load resolver "node"  import/no-duplicates
  1:1  error  Resolve error: unable to load resolver "node"  import/extensions
  1:1  error  Resolve error: unable to load resolver "node"  import/order
  1:1  error  Resolve error: unable to load resolver "node"  import/no-self-import
  1:1  error  Resolve error: unable to load resolver "node"  import/no-cycle
  6:8  error  Unable to resolve path to module 'graphql'     import/no-unresolved

Most helpful comment

Just in case anyone else comes across this, there is a discussion here: https://github.com/benmosher/eslint-plugin-import/issues/828

The workaround is to add eslint-import-resolver-node to package dependencies

(works for me)

All 4 comments

Someone would need to provide their own resolver if pnp requires extra support - I鈥檇 suggest filing an issue on yarn itself about it.

Another maintainer can reopen if they disagree, but i have no plans to add support for something that doesn鈥檛 ship with node; I鈥檇 have preferred the webpack resolver not be in this repo either.

Just in case anyone else comes across this, there is a discussion here: https://github.com/benmosher/eslint-plugin-import/issues/828

The workaround is to add eslint-import-resolver-node to package dependencies

(works for me)

@ljharb I think you confused the issue
Resolve error: unable to load resolver "node" means that eslint-import-resolver-node can't be found. Not the module of the bundle can't be resolved but ESlint can't find the module.

The issue is about resolving of ESLint resolve plugins. Because developers pass only the name node in config and it is converted to something like require('eslint-import-resolver-node') which can't work in PnP environment. PnP allows only modules listed in package.json to be required. And as I understand eslint-import-resolver-node is defined and required in 2 different packages.

So do you think we should reopen it?

@constgen no. eslint doesn't resolve the name of module resolvers, eslint-plugin-import does. Separately, anything that works in npm but not in PnP at this point is a bug in PnP - i have no idea why require('eslint-import-resolver-node') wouldn't work (altho you might have to explicitly add it as a dep, per https://github.com/benmosher/eslint-plugin-import/issues/1434#issuecomment-521189117).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yutin1987 picture yutin1987  路  3Comments

daltonamitchell picture daltonamitchell  路  3Comments

migueloller picture migueloller  路  3Comments

pcorpet picture pcorpet  路  3Comments

yutin1987 picture yutin1987  路  3Comments