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

Unable to resolve path to module 'katex' with eslint-import-resolver-webpack

Open
#2,293 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

`exports` support
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

import katex from "katex"; is valid according to both native Node.js and webpack. But eslint-import-resolver-webpack is unable to resolve it, leading to a spurious error Unable to resolve path to module 'katex'. This might have something to do with the exports map in katex/package.json.

Complete reproducible example:

src.js

import katex from "katex";
console.log("Hello KaTeX", katex.version);

.eslintrc.json

{
  "env": {
    "es6": true
  },
  "parserOptions": {
    "sourceType": "module"
  },
  "plugins": ["import"],
  "rules": {
    "import/no-unresolved": "error"
  },
  "settings": {
    "import/resolver": "webpack"
  }
}

package.json

{
  "type": "module",
  "dependencies": {
    "eslint": "8.1.0",
    "eslint-import-resolver-webpack": "0.13.2",
    "eslint-plugin-import": "2.25.2",
    "katex": "0.15.1",
    "webpack": "5.61.0",
    "webpack-cli": "4.9.1"
  }
}
$ npm i
…

$ node src.js
Hello KaTeX 0.15.1

$ npx webpack --mode=production
…
webpack 5.61.0 compiled with 3 warnings in 2988 ms

$ node dist/main.js 
Hello KaTeX 0.15.1

$ npx eslint src.js

/tmp/test/src.js
  1:19  error  Unable to resolve path to module 'katex'  import/no-unresolved

✖ 1 problem (1 error, 0 warnings)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible files src.js, .eslintrc.json, and package.json, then run the listed Node.js, webpack, and eslint commands to confirm the discrepancy. Inspect how eslint-import-resolver-webpack handles the exports map in katex/package.json and the import/no-unresolved rule. Done means the valid katex import no longer reports an unresolved-module error while the reproduction still builds and runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript, webpack
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.