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

Unresolved dependencies when "exports" field property's value is array #670

Closed
sosukesuzuki opened this issue Dec 1, 2020 · 6 comments · Fixed by #693
Closed

Unresolved dependencies when "exports" field property's value is array #670

sosukesuzuki opened this issue Dec 1, 2020 · 6 comments · Fixed by #693

Comments

@sosukesuzuki
Copy link
Contributor

Expected Behavior

Successful bundle for packages whose "exports" field in package.json is array like below:

{
  "name": "pkg",
  "exports": {
    ".": "./main.js",
    "./util": [
      {
        "import": "./util.mjs"
      },
      "./util.js"
    ]
  }
}

Actual Behavior

Unable to bundle, output like this:

(!) Plugin node-resolve: Package subpath './util' is not defined by "exports" in /Users/sosukesuzuki/development/rollup-plugin-node-resolve-11-bug-repro/pkg/package.json
(!) Unresolved dependencies

Additional Information

Please see the reproduce repository link. Also this bug was found from prettier/prettier#9804.

If this is my misunderstand, sorry please close this.

@LarsDenBakker
Copy link
Contributor

@guybedford do we support this kind of format in node? I couldn't find it in the docs.

@lukastaegert
Copy link
Member

I tried it out and it seems to be supported in latest Node 14. I am also seeing this in the wild as used by yargs-parser, which is why Rollup cannot update node-resolve right away. But I also could not find any official documentation, which is odd. The only thing I could find was Webpack's take on it here, but I would hardly consider that official: https://webpack.js.org/guides/package-exports/

As it appears to be supported, maybe this is just a documentation issue cc @guybedford ?

@guybedford
Copy link
Contributor

Yes it is supported and in the spec (per the modules documentation on the Node.js project) but not explicitly documented as it is not a recommended feature for any use cases.

This comes from the builtins fallback feature that import maps originally supported, and Node.js can provide support for that similarly if necessary in future by supporting. I believe webpack may be encouraging the array form via https://webpack.js.org/guides/package-exports/#alternatives but we don't encourage using it in Node.js.

@lukastaegert
Copy link
Member

That means we should support it nonetheless?

per the modules documentation on the Node.js project

Where is that?

@guybedford
Copy link
Contributor

Yes I agree it should be supported.

The exact resolver specification can be found at https://nodejs.org/dist/latest-v15.x/docs/api/esm.html#esm_resolver_algorithm_specification, and the array resolution is detailed in PACKAGE_TARGET_RESOLVE under the array condition.

@LarsDenBakker
Copy link
Contributor

Will pick this up.

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

Successfully merging a pull request may close this issue.

5 participants