Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andersk opened this issue Nov 5, 2021 · 1 comment

Comments

@andersk
Copy link
Contributor

andersk commented Nov 5, 2021

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)
@ljharb
Copy link
Member

ljharb commented Nov 5, 2021

The issue is that katex has entry points defined in exports that do not, for backwards compatibility, have corresponding files on the filesystem for older nodes to resolve.

This package uses resolve, and neither has support yet for exports. So, either katex will have to add those files (which it should anyways, since it doesn't declare engines.node, which means it probably works on every node version), or, you'll need to use import/ignore on that dependency until we're able to add that support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants