import-js / import-js/eslint-plugin-import

Rule `import/no-unresolved` raise false positive when there is no `main` field in the `package.json`

Open
#2,132 40 comments 20 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

**What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.**

```js
import GBAEmulator, { GbaContext } from 'react-gbajs'
```
[_Full code_](https://github.com/macabeus/klo-gba.js/blob/master/brush/src/components/Emulator/index.js)

```bash
./node_modules/.bin/eslint .
```

**What did you expect to happen?**
Should raise no error. This package is present in the `node_modules`.

An important note:
Since it's only for the browser, it has the field `browser` instead of `main` in its `package.json` ([link](https://github.com/macabeus/react-gbajs/blob/87ef927edbfd24adc1370f95d650edc32570ac83/package.json#L5)). I made it following [the NPM documentation](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#browser).
Despite that, I noticed that by adding the field `main` in its `package.json`, the error suppress - but it doesn't look correct.

**What actually happened? Please copy-paste the actual, raw output from ESLint.**
```
/Users/macabeus/ApenasMeu/klo-gba.js/brush/src/components/Emulator/index.js
2:41 error Unable to resolve path to module 'react-gbajs' import/no-unresolved

/Users/macabeus/ApenasMeu/klo-gba.js/brush/src/components/KloGbaSidebar/Hacks/index.js
7:28 error Unable to resolve path to module 'react-gbajs' import/no-unresolved

/Users/macabeus/ApenasMeu/klo-gba.js/brush/src/hooks/useGbaSaveRestoreState.js
2:28 error Unable to resolve path to module 'react-gbajs' import/no-unresolved

/Users/macabeus/ApenasMeu/klo-gba.js/brush/src/index.js
8:29 error Unable to resolve path to module 'react-gbajs' import/no-unresolved

/Users/macabeus/ApenasMeu/klo-gba.js/brush/src/providers/VisionProvider.js
4:28 error Unable to resolve path to module 'react-gbajs' import/no-unresolved

✖ 5 problems (5 errors, 0 warnings)

✨ Done in 4.73s.
```

**Steps to reproduce this issue:**

1. Clone this repository: https://github.com/macabeus/klo-gba.js
1. Run `yarn` on its root
1. `cd brush`
2. `yarn run lint`

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure from klo-gba.js by running yarn run lint in brush, using the imports in the listed Emulator, KloGbaSidebar/Hacks, useGbaSaveRestoreState, index, and VisionProvider files. Inspect react-gbajs/package.json, especially its browser field and absent main field, then trace the import/no-unresolved rule's resolution entry point. Done means the browser-only package resolves without false-positive errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.