Skip to content

Conditional exports in resolve@next #209

Closed

Description

@coreyfarrell

It's nice that the next version provides an ES module wrapper using conditional exports. One suggestion could you drop the require condition? The following seems to work:

".": {
  "import": "./index.mjs",
  "default": "./index.js"
}

The big difference is that require('resolve') will not print ExperimentalWarning: Conditional exports is an experimental feature. as default is not part of the conditional exports feature where require is. import('resolve') will produce the warning but that seems reasonable (hopefully this warning will not stay for long).

Also for my own information can you explain why you list sub-paths as:

		"./core": [
			{
				"default": "./lib/core.js"
			},
			"./lib/core.js"
		],

Couldn't this be reduced to "./core": "./lib/core.js"?

Activity

  1. ljharb commented on Jan 25, 2020

    @ljharb
    Member

    Dropping the require condition makes sense, yes.

    The reason that the array is always required is that node v13.0 and v13.1 have a bug where although ESM is flagged, "exports" is still read, and they do not understand the object syntax. Thus, the arrays will have to be used in every package i maintain forever, including this one.

  2. coreyfarrell commented on Jan 25, 2020

    @coreyfarrell
    Author

    Wouldn't 13.0 / 13.1 understand:

    "exports": {
      ".": [
        {
          "import": "./index.mjs",
          "default": "./index.js"
        },
        "./index.js"
      ],
      "./core": "./lib/core.js"
    }

    I understand why you need the array notation for the main export which provides the ES module wrapper but for the sub-path remaps which do not have conditional exports I'm not sure why you need object notation at all?

  3. ljharb commented on Jan 25, 2020

    @ljharb
    Member

    If i want the subpaths to work in node 13.0 and 13.1, they also need the array form.

  4. added a commit that references this issue on Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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