rollup-plugin-node-externals icon indicating copy to clipboard operation
rollup-plugin-node-externals copied to clipboard

(fix): eslint import/no-unresolved issue

Open mzonski opened this issue 1 year ago • 2 comments

Because of the missing 'main' key the eslint-plugin-import:resolver:node cannot resolve the package as a directory, thus throwing import/unresolved error/warning.

Here's the link to the place in code that is failing: https://github.com/browserify/resolve/blob/fd788d94d037e32d4f4be948e2f7e15f6981f004/lib/sync.js#L180

If the main is not set, it defaults to index.js in the package's root folder, you're exporting index.js and declaration in the dist directory thus it's producing an error in the code pointed upper.

mzonski avatar Aug 21 '24 17:08 mzonski

In ESM packages like this one, the main field is superseded by the exports field. See the Node's documentation about exports.

I'm afraid the browserify/resolve package is outdated. They should support exports. I suggest you file an issue on their repository because this is not something I intend to support for them.

Leaving this PR open for now, but will probably close it with won't fix soon.

Septh avatar Aug 25 '24 23:08 Septh

I can't say you are wrong with these assumptions, but I cannot tell that mine are bad. By merging this Pull request you will greatly improve backward compatibility with the various tools used across Node ecosystem.

It's fine for me if you decide not to merge these changes, but let me tell you - this is the only package in my rollup configuration throwing the unresolved error due to lack of the "main" definition - check it here

In this pull request they're trying to add support for the default node import behavior. I believe I will find a wife sooner than this PR is merged or they do proper code changes, and then the ESLint plugin resolver needs to be updated with these changes. It's a long chain of events.

mzonski avatar Aug 27 '24 13:08 mzonski