eslint-plugin-import: `no-unresolved` is not aware of `exports` definition in `package.json`
From this announcement
Package entry points and the package.json “exports” field
There are now two fields that can define entry points for a package: “main” and“exports”. The “main” field is supported in all versions of Node.js, but its capabilities are limited: it only defines the main entry point of the package. A new package.json field “exports” can also define the main entry point, along with subpaths. It also provides encapsulation, where only the paths explicitly defined in “exports” are available for importing. “exports” applies to both CommonJS and ES module packages, whether used via require or import.
Might need to be fix in resolve
package…
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 73
- Comments: 71 (30 by maintainers)
Commits related to this issue
- Remove import eslint module The import module does not currenty handle package exports. The author is apparently of the opinion that exports should not use renaming features. Until this is fixed, all... — committed to firebase/firebase-tools by inlined 3 years ago
- Remove import eslint module The import module does not currenty handle package exports. The author is apparently of the opinion that exports should not use renaming features. Until this is fixed, all... — committed to firebase/firebase-tools by inlined 3 years ago
- Bugbash fixes (#3644) * Print function names on validation errors, not [Object object] * Require all necessary APIs * Remove import eslint module The import module does not currenty handle p... — committed to firebase/firebase-tools by inlined 3 years ago
- Bugbash fixes (#3644) * Print function names on validation errors, not [Object object] * Require all necessary APIs * Remove import eslint module The import module does not currenty handle p... — committed to devpeerapong/firebase-tools by inlined 3 years ago
- test(eslint): let ESLint recognize the `exports` field in `package.json` `eslint-plugin-import@2.26.0` does not detect the `exports` field in `package.json`. https://github.com/import-js/eslint-plugi... — committed to sounisi5011/npm-packages by sounisi5011 2 years ago
- chore(repo): support `exports` field in `package.json` (#405) * test(eslint): let ESLint recognize the `exports` field in `package.json` `eslint-plugin-import@2.26.0` does not detect the `expo... — committed to sounisi5011/npm-packages by sounisi5011 2 years ago
- feat: ignore import/no-unresolved false-positives As a temporary workaround for https://github.com/import-js/eslint-plugin-import/issues/1810 Signed-off-by: Kevin Locke <kevin@kevinlocke.name> — committed to kevinoid/eslint-config-kevinoid by kevinoid 2 years ago
- fix: Add root `firebase.js` as complement to pkg named export to prevent no-unresolved eslint error https://github.com/import-js/eslint-plugin-import/issues/1810 — committed to ecomplus/cloud-commerce by leomp12 2 years ago
- disable import/no-unresolved linting rule Needs to be disabled because it currently isn't aware of the exports definition in package.json (see [issue](https://github.com/import-js/eslint-plugin-impor... — committed to jscheffner/hapi-auth-any by jscheffner 2 years ago
- disable import/no-unresolved linting rule Needs to be disabled because it currently isn't aware of the exports definition in package.json (see [issue](https://github.com/import-js/eslint-plugin-impor... — committed to jscheffner/hapi-auth-any by jscheffner 2 years ago
- fix: Update `import logger from 'firebase-functions/logger'` for firebase-functions v4 Specify ignored "unresolved" imports on eslintrc to deal with https://github.com/import-js/eslint-plugin-import/... — committed to ecomplus/cloud-commerce by leomp12 2 years ago
- ci(functions): 💚 use diffrent import resolver for firebase typescript this is a workaround for https://github.com/import-js/eslint-plugin-import/issues/1810 — committed to cat-acronym-team/cat-me-if-you-can by nstringham 2 years ago
- fix(eslint-config): undo import changes eslint-plugin-import is just all sorts of fucking busted: https://github.com/import-js/eslint-plugin-import/issues/1810 — committed to JaneJeon/dev by JaneJeon a year ago
- chore: turn off `import/no-unresolved` related issue https://github.com/import-js/eslint-plugin-import/issues/1810 — committed to strapi/strapi by joshuaellis 10 months ago
I just published a resolver package that solves this issue using resolve.exports: https://www.npmjs.com/package/eslint-import-resolver-exports
It’s currently beta but seems to work for most of my projects. Feedback appreciated.
You can use https://github.com/import-js/eslint-import-resolver-typescript which supports
exports
inpackage.json
instead.I workaround the issue by using no-unresolved’s
ignore
option:Fixing resolve would be of much larger impact than a new resolver.
Of course, I didn’t close this issue. 🤣
@inlined if google wants to help make it happen faster, please feel free to visit https://github.com/browserify/resolve?sponsor=1
@inlined why would your Google SDKs be using
exports
, withoutmain
, in a way that’s not backwards-compatible??I’m not wedded to any particular outcome, but it’s unacceptable to me that all discussion on the topic should be summarily silenced.
Not deleted by you then, but it was emailed to anyone who subscribes to this thread.
Your summary would be fine; your conclusion would only distract.
I would appreciate if you would allow my condensed argument to stand as a matter of public record. Please?
Hi @conartist6, I already have a working resolver I shared in my comment. I gladly accept contributions 😃
@vvo gitignore is so they don’t get committed; you DO want them published, which means you have to have a
.npmignore
that duplicates your gitignore but removes the lines that ignore build output.For what it’s worth, here’s how I solved this situation for a package of mine.
The import style of the library is:
I updated my package.json build steps with:
What this does is make copies of the build output files right before npm publish and remove them right after. A bit hacky but it definitely works and will ensure the package works well even on bundlers not supporting the exports: {} field of package.json.
Thanks to the maintainers of eslint-plugin-import for the very hard work they do.
We control our execution environment and do not need to be backwards compatible to versions that don’t support exports (every supported LTS of Node supports exports). Also, putting a root export would muddy project structure. It is quite common to have a
/src
and/lib
folder for typescript projects. Withexports
it is quite understandable to removelib
from documented import paths.We are using
main
. We also useexports
for submodule paths so we can omit thelib
folder generated by TypeScript.For example,
./lib/v2/providers/https.js
is exported at./v2/https
. See github.com/firebase/firebase-functions for more info.I feel that you have abused your position as a moderator to protect your image in the face of reasoned dissent, so I can’t say I’m that thrilled with you at the moment.
I think the sane solution here is to don’t worry at all about any unmaintained Node.js version, it’s said, don’t provide support for anything older than Node.js v18.
Yup. Doing unpaid volunteer work doesn’t create a lot of free time.
I’m proposing to fix this by writing a new resolver. I’ve been experimenting recently (with great success, I feel) in making code sync/async agnostic by making aggressive use of the strategy pattern, which allows you to write functionally pure code which makes requests to and receives responses from a stateful core. Because that request/response mechanism is
yield
, the core is able to complete the request synchronously, or it may leave the generator suspended while it waits for async lookups to complete.Would anyone be interested in collaborating me on a project like that if it would fix this issue once and for all?
Currently what’s in the readme is all I have. I think it’s best to use this as a fallback in addition to other resolvers as it only supports
main
,module
,exports
and nothing else. The readme shows how to use it with TypeScript resolver for example. You should probably keep using Webpack’s resolver too.Check the
resolve.exports
docs for configuration options.Thanks updated my comment to add committed. Also, I am using the “files: [“dist”, “express”, “next”]” setting of npm.
Indeed, but I don’t want to see these files in my editor (VSCode), they would still appear as grayed out I guess. But I will still add them to gitignore so they never get
publishedcommitted.@inlined i’m not “of the opinion that exports should not use renaming features”, i’m of the opinion that you have a really simple workaround while you wait.
None of my “opinions” are delaying
exports
support - the work is difficult and nobody else is doing it, and I have limited time. It will be done eventually.Right - but that’s not backwards-compatible to pre-exports node. However, if you created an actual
./v2/https.js
file that re-exported that provider, then not only would your package be backwards-compatible, but you wouldn’t be blocked onresolve
gettingexports
support.