import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.54k stars 1.57k forks source link

`import/no-unresolved` triggers when importing `pixi.js/advanced-blend-modes`. #3088

Open guillaumebrunerie opened 1 week ago

guillaumebrunerie commented 1 week ago

With PixiJS v8, advanced blend modes are imported as follows (see for instance https://pixijs.com/8.x/examples/basic/blend-modes):

import "pixi.js/advanced-blend-modes";

However, this triggers the lint error Unable to resolve path to module 'pixi.js/advanced-blend-modes'. [import/no-unresolved].

Here is the (I think) relevant part of PixiJS's package.json (seems correct to me, but I don’t know much about those things):

{
  "exports": {
    "./advanced-blend-modes": {
      "import": {
        "default": "./lib/advanced-blend-modes/init.mjs"
      },
      "require": {
        "default": "./lib/advanced-blend-modes/init.js"
      }
    }
  }
}

Note that if I write the following:

import "pixi.js/lib/advanced-blend-modes";

then the lint error goes away, but the import itself doesn’t work anymore, I get the following error from Vite:

[plugin:vite:import-analysis] Missing "./lib/advanced-blend-modes" specifier in "pixi.js" package

I'm not sure if it’s an issue in eslint-plugin-import, in PixiJS, or if I misconfigured something? I’m using ESLint 8.57 with a .eslintrc and "type": "module" in my package.json.

ljharb commented 1 week ago

This plugin does not yet support exports, until resolve does.

Ideally, the package would keep the LHS and RHS of "exports" the same, so that it gracefully degrades - otherwise until resolve (and thus, us) adds support for exports, you'd need to add the package to the ignored imports setting.

guillaumebrunerie commented 1 week ago

In what way does resolve not support exports? I tried to run require.resolve("pixi.js/advanced-blend-modes") in the node REPL in the root directory of my project, and got the expected result: [...]/node_modules/pixi.js/lib/advanced-blend-modes/init.js.

ljharb commented 1 week ago

in any way - i'm talking about https://npmjs.com/resolve