Skip to content

eslint-import-resolver-node can't handle "exports" #1884

Closed
@wojtekmaj

Description

@wojtekmaj

🐛 Bug Report

"exports" field seems to be ignored by eslint-import-resolver-node, resulting with unexpected error thrown by import/no-unresolved rule even though Node is capable of resolving the paths.

https://nodejs.org/api/esm.html#esm_package_entry_points

To Reproduce

Steps to reproduce the behavior:

I have a simple utils package in my workspace, that's shaped like this:

/dist
  array.js
  … 
/src
  array.js
  …
package.json

package.json:

{
  "name": "@my-org/utils",
  "version": "1.0.0",
  "exports": {
    "./array": "./dist/array.js",
    "./boolean": "./dist/boolean.js",
    "./math": "./dist/math.js",
    "./number": "./dist/number.js",
    "./object": "./dist/object.js",
    "./promise": "./dist/promise.js",
    "./string": "./dist/string.js"
  }
}

This allows me to use it in my main project by importing utils like this:

import { min } from '@my-org/utils/math'

This works both in native ES modules environment in Node 14, and in code transpiled by Babel. But this line is flagged by import/no-unresolved.

Expected behavior

"exports" to be respected and understood by eslint-import-resolver

Link to repo

https://github.com/wojtekmaj/resolve-exports-issue

envinfo

  System:
    OS: macOS 11.0
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  Binaries:
    Node: 14.5.0 - /usr/local/bin/node
    Yarn: 2.1.1 - /usr/local/bin/yarn
    npm: 6.14.5 - /usr/local/bin/npm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions