Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Does this support the "exports" property in package.json? #863

Open
trusktr opened this issue Jan 26, 2020 · 1 comment
Open

Does this support the "exports" property in package.json? #863

trusktr opened this issue Jan 26, 2020 · 1 comment

Comments

@trusktr
Copy link

trusktr commented Jan 26, 2020

I am using "exports" in new project's package.json that I run in Node.js v13.2+ and it works great.

(Note, specifically Node v13.2+ because 13.2 introduced a feature where mapping a folder in exports causes it to behave exactly like the desired functionality of mainDir that is expressed in nodejs/node#14970).

In particular the feature that I'm wondering about is, if a path is mapped to another path using exports, then the consumer of the package can import anything from that mapped folder and subfolders. Prior to Node 13.2 mapping a folder would cause any of its sub-folders to be unavailable for import.

For example, my exports field is like this normally:

    "exports": {
        ".": "./dist/index.js",
        "./": "./dist/"
    },

And this means a user can:

// causes Node to load the-package/dist/Foo.js:
import {Foo} from 'the-package/Foo.js'

// causes Node to load the-package/dist/index.js:
import {blah} from 'the-package'

Does esm support this same functionality? I'm looking for something to fallback to until Electron is released with Node 14. They are on Node 12 right now, and only ship with LTS Node.

@damianobarbati
Copy link

OT

@trusktr are you using named imports in production with node 13 today? I'm asking because most of libs do not provide exports (i.e: lodash-es) thus named import do not work with them, and this is preventing me from upgrading to v13+esm. Did you manage to work it around?

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

No branches or pull requests

2 participants