-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support for package.json exports
and imports
?
#1868
Comments
Yes, both should be supported (altho "imports" is super brand new, like, less than a week). However, support first needs to be added in |
Awesome! Glad to hear it. Thanks for the reply. This issue can track its progress then! Look forward to it. |
@ljharb any movement on this? |
@clintwood not quite yet - browserify/resolve#224 is still in progress, which would be the first step. |
@ljharb - I see - thanks for the feedback! Things have become a little complicated in nodeland 😉 |
With Node.js adopting a standard for packages to declare their exports, this rule may not be useful anymore. It should be legal to import any valid export from a package. An open [issue] on eslint-plugin-import tracks this ecosystem feature and when that resolves there may be a better rule to enable. [issue]: import-js/eslint-plugin-import#1868
@ljharb will the modifications to the |
@ctavan once resolve supports that, yes. |
Any workaround in the meantime? Getting |
Best workaround is just to turn off the rule until they add support for routing via package.json |
A package that doesn’t provide equivalent CJS paths for exports paths isn’t back-compat and is thus being user-hostile, so this shouldn’t require workarounds most of the time. |
If using Yarn Berry's PnP, you can use a custom resolver I wrote such as https://github.com/tophat/eslint-import-resolver-require (just delegates to require.resolve). |
Not all packages are open source and made available for public consumption. In some closed development systems, a minimum version of nodejs is set allowing exclusive access to features such as subpath fields. |
True enough. Unfortunately those will have to use the above resolver or wait until proper exports support is added to resolve. |
import/no-unresolved
raise false positive when there is no main
field in the package.json
#2132
Why not use https://github.com/webpack/enhanced-resolve which supports export fields instead of https://github.com/browserify/resolve?
I think modifying this file a bit should be enough, right? |
I'm using this in eslint rules file
|
I had to modify @MikeG96's code to this to fully ignore these errors for imported modules with the # syntax:
|
@jrj2211 voicing support is unnecessary; there is a 100% chance this feature will eventually be implemented. |
Hi all, FYI I am successfully using this tiny ESLint import resolver to support ESM modules imports via package.json exports map: https://gist.github.com/danielweck/cd63af8e9a8b3492abacc312af9f28fd Duplicate issue? #1810 |
Indeed, duplicate of #1810. |
Was support for this added? I'm still seeing |
I think this is not yet completed, but has been moved to #1810 - there are also multiple workarounds in that thread, including:
@ljharb, maybe the discussion in #1810 could be reopened to allow comments again? |
May help others: the final piece I required to solve |
Sorry if this was posted, I did search quite a few things before posting :-P
So just came across this today, https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_packages - not sure how i missed it for so long but it appears that the internal
imports
mapping was just released in a recent.x
version of v14.Basically it allows node to resolve situations like Typescript
paths
would. There are a few cases here that seem like they are fairly advanced to handle properly, and it doesn't seem like it works at the moment, although just initial testing so far.While I know that there are import resolvers that would allow defining the rules manually, since this is an official node feature already launched in the LTS version of node, it probably makes sense to support it with the default node resolver?
Given the above, I can run the following in node (no feature flags needed)
Running things with some flags to provide helper fns (no require.resolve by default) we do see:
Also just realized this even works if not using
"type": "module"
for standard require-based modules, although with require.resolve it doesnt return file path:The text was updated successfully, but these errors were encountered: