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

import/no-unresolved is throwed on nested module path #2357

Closed
kot-shrodingera opened this issue Jan 15, 2022 · 5 comments
Closed

import/no-unresolved is throwed on nested module path #2357

kot-shrodingera opened this issue Jan 15, 2022 · 5 comments

Comments

@kot-shrodingera
Copy link

kot-shrodingera commented Jan 15, 2022

I have simple project, using FormData and fileFromPath from formdata-node package

package.json

{
  "name": "test",
  "version": "1.0.0",
  "type": "module",
  "devDependencies": {
    "eslint": "8.6.0",
    "eslint-plugin-import": "2.25.4"
  },
  "dependencies": {
    "formdata-node": "4.3.2"
  }
}

.eslintrc.json

{
  "parserOptions": {
    "ecmaVersion": 2021,
    "sourceType": "module"
  },
  "ignorePatterns": ["node_modules"],
  "extends": [
    "eslint:recommended",
    "plugin:import/recommended"
  ]
}

test.js

import { fileFromPath } from 'formdata-node/file-from-path';
import { FormData } from 'formdata-node';

(async () => {
  const formData = new FormData();
  const file = await fileFromPath('dist/fonbet.js', {
    type: 'text/javascript',
  });
  formData.append('filename', file);
})();

npx eslint .\test.js returns

  1:30  error  Unable to resolve path to module 'formdata-node/file-from-path'  import/no-unresolved

So no error for importing FormData from 'formdata-node', but it is on importing fileFromPath from 'formdata-node/file-from-path'. Maybe this is because nested path? But node runs my script without errors
Am missing something in my config? I tried to add this to .eslintrc.json

"settings": {
    "import/resolver": "node"
  }

But this doesn't help

@ljharb
Copy link
Member

ljharb commented Jan 16, 2022

That's because that import path relies on "exports" in that package - but https://unpkg.com/browse/[email protected]/package.json doesn't exist (as it should, for backwards compatibility).

This is also because this plugin uses resolve, which doesn't yet support the "exports" field.

The ideal solution is for that package to add top-level files so that pre-exports node, and this plugin, can resolve them. Otherwise, you'll need to override that warning until resolve supports "exports".

@kot-shrodingera
Copy link
Author

I thought that if resolve cannot properly import, execution will also fail?

@ljharb
Copy link
Member

ljharb commented Jan 16, 2022

resolve isn't used at runtime. node can properly require it, so it'll work fine.

@kot-shrodingera
Copy link
Author

Weren't conditional exports introduced quite some time ago? Why they aren't supported and when will they be?
Sorry if question is stupid, I'm just trying to figure it out

@ljharb
Copy link
Member

ljharb commented Jan 16, 2022

The "exports" field itself was released in May 2020, in the middle of a pandemic, and that pandemic still continues.

Another reason that it hasn't been pressing is that most packages that add "exports", care about backwards compatibility, and so resolution works the same with or without it for all documented entry points. It's only when a package drops "main" entirely, goes ESM-only, or fails to provide top-level entry points for back compat (like this one), that it becomes a problem.

They will be supported when resolve supports them. No date is promised.

I'm going to close this since there's nothing for eslint-plugin-import to do, specifically.

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

No branches or pull requests

2 participants