eslint-plugin-import: ESM: Unable to resolve path to module 'got' import/no-unresolved

Unable to resolve path to module ‘got’ import/no-unresolved

// Unable to resolve path to module 'got'  import/no-unresolved
import got from 'got';
  • got v12.0.0
  • eslint v8.5.0
  • eslint-plugin-import 2.25.3

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 23 (13 by maintainers)

Most upvoted comments

It is a very explicit and intentional choice to avoid using the built-in require.resolve.

Again, ESM-only packages are the problem - this plugin supports transpiled ESM, and not native ESM. is-ip seems to work because the index.js and lack of main means pre-exports node would try and fail to load that file.

When resolve gains support for “exports”, it will support native ESM too.

While this support is quite overdue here, ESM-only packages remain exceedingly user-hostile, and i strongly suggest aggressively avoiding them. There’s always an alternative non-ESM-only (and thus better) package to choose.

So it’s still related to exports field support, right?

Just guessing, but maybe it’s because got has no index.js. For example another pure ESM module, https://github.com/sindresorhus/is-ip, is resolved fine by this plugin and it has a index.js, which by default is picked up by node’s CJS resolution.

Those modules that the no-unresolved rule fails to find appear to be missing main and only defining exports (as node documents).

Same problem, caused by the same maintainer - altho in that case, it doesn’t have any runtime values, so you should be using import type.

That’s a strong and wildly incorrect opinion.

Native ESM has tons of downsides and offers no benefits over CJS. Both are first-class module systems in node, so yes, native ESM should work, but the ecosystem isn’t ready to support it yet.

I’m going to close this.

ESM should work. CJS should be deprecated.

Thanks!

In this case, the latest version of got drops support for CJS, and as such, can’t be resolved by our CJS-only resolution mechanism. If you’re using native ESM, this plugin won’t help you, because it’s designed for use with CJS, or transpiled ESM (Babel/TS).

If you downgrade to got v11, or switch to a package author that isn’t user-hostile, then you should see everything resolve correctly.