Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

node v13.0-v13.1 errors on require of a module with "exports" defined #446

Closed
ljharb opened this issue Nov 25, 2019 · 13 comments
Closed

node v13.0-v13.1 errors on require of a module with "exports" defined #446

ljharb opened this issue Nov 25, 2019 · 13 comments
Labels
modules-agenda To be discussed in a meeting

Comments

@ljharb
Copy link
Member

ljharb commented Nov 25, 2019

I get this error: Error: Package exports for 'path/to/package' do not define a valid '.' target

when, in the node v13.1 repl (where the flag should be required), I have:

     "main": "index",
     "exports": {
         ".": {
             "default": "./node.js"
         }
     },

I would have expected "exports" to have no effect prior to v13.2 when no modules flag is provided. It throws for me on v13.0 and v13.1, although not on v12.

This seems like a pretty serious back compat issue.

@ljharb
Copy link
Member Author

ljharb commented Nov 25, 2019

(When I switch it to ".": "./node.js" it is requireable on v13.0 and v13.1)

@ljharb
Copy link
Member Author

ljharb commented Nov 25, 2019

cc @guybedford @MylesBorins

@MylesBorins
Copy link
Contributor

MylesBorins commented Nov 25, 2019 via email

@ljharb
Copy link
Member Author

ljharb commented Nov 25, 2019

No issues I can find with v12.

I don't mean, a back compat issue that we could fix in older v13 minors (altho that would be ideal), i mean an issue with keeping "exports" moving forward, because it means any package that uses the object form can never work on those two minors of node.

Is there any version of the object form that will work on v13.0 and v13.1?

@MylesBorins
Copy link
Contributor

MylesBorins commented Nov 25, 2019 via email

@ljharb
Copy link
Member Author

ljharb commented Nov 25, 2019

The point of a dual mode package is that it's not a breaking change to add ESM to your package; this way it will always be a breaking change for v13.0 and v13.1. Semver does not care about whether a release is "supported" - support (by the platform author) is irrelevant.

@MylesBorins
Copy link
Contributor

Fwiw throwing with the default is likely because that sugar was not supported before 13.2.0

The throwing when no dot declared appears to be similar behavior to what was identified in this issue

nodejs/node#30633

@MylesBorins
Copy link
Contributor

Semver does not care about whether a release is "supported" - support (by the platform author) is irrelevant

Semver minor adds new API surfaces, if you try to use them in earlier versions that will "break". By this definition of semver all minor changes would be considered breaking

13.x is an experimental line that will be EOL in 5 months. We should not limit our implementation to support earlier releases in this release line

@ljharb
Copy link
Member Author

ljharb commented Nov 25, 2019

and there's no way we'd be able to do a 13.0 and/or 13.1 backport patch that disabled "exports" checking when the experimental flag was not provided?

@MylesBorins
Copy link
Contributor

MylesBorins commented Nov 25, 2019 via email

@ljharb ljharb added the modules-agenda To be discussed in a meeting label Nov 25, 2019
@ljharb ljharb changed the title node v13.1 errors on require of a module with "exports" defined node v13.0-v13.1 errors on require of a module with "exports" defined Nov 25, 2019
@ljharb
Copy link
Member Author

ljharb commented Nov 25, 2019

What this means, effectively, is that if I ever add "exports" to my package.json with the object form in ., I can never support node v13.0 or v13.1 - thus, as a package author, that means I'll probably never use "exports", and thus never use ESM.

@jkrems
Copy link
Contributor

jkrems commented Nov 25, 2019

Is it possible to use the following form?

     "main": "index",
     "exports": {
         ".": [{
             "default": "./node.js"
         }, "./node.js"]
     },

I assume most people will not go out of their way to support specific minor versions of non-LTS releases of node but maybe the above will allow more ambitious maintainers to do it?

@ljharb
Copy link
Member Author

ljharb commented Nov 25, 2019

@jkrems beautiful :-) that works perfectly and allows the exact support I need.

In that case, especially given Myles' strong resistance to backporting patches into v13.0 and v13.1, I'm content to close this with the understanding that the "best practice" recommendation for maximal backwards compatibility will be to always use an array for . that has the object form, and the string form.

@ljharb ljharb closed this as completed Nov 25, 2019
bluelovers added a commit to bluelovers/nanoid that referenced this issue Apr 12, 2020
nodejs/modules#446

    "Error: Package exports for '/data/data/com.termux/files/home/.config/yarn/global/node_modules/nanoid' do not define a valid '.' target\n"
bluelovers added a commit to bluelovers/dual-publish that referenced this issue Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
modules-agenda To be discussed in a meeting
Projects
None yet
Development

No branches or pull requests

3 participants