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

Incorrect resolution of package with conditional exports #8221

Closed
marcoreni opened this issue Jun 16, 2022 · 1 comment
Closed

Incorrect resolution of package with conditional exports #8221

marcoreni opened this issue Jun 16, 2022 · 1 comment

Comments

@marcoreni
Copy link

🐛 bug report

When trying to build a webapp with an isomorphic dependency that uses NodeJS conditional exports, the build loads the NodeJS version of the dependency.

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  "dependencies": {
    "crypto-hash": "^2.0.1",
    "parcel": "^2.6.0"
  },
  "source": "index.html",
  "scripts": {
    "build": "parcel build --no-autoinstall"
  }
}

index.js

import { sha256 } from "crypto-hash";

sha256("foobar").then((data) => console.log(data));

index.html

<html>
  <body>
    <script type="module" src="index.js"></script>
  </body>
</html>

🤔 Expected Behavior

I expected Parcel to use the browser version of the library.

😯 Current Behavior

Parcel loads the NodeJS version of the library and attempts to install polyfills:


🚨 Build failed.

@parcel/core: Failed to resolve 'node:buffer' from './node_modules/crypto-hash/index.js'

  /Volumes/Workspace/work/data/parcel-repro/node_modules/crypto-hash/index.js:1:22
  > 1 | import {Buffer} from 'node:buffer';
  >   |                      ^^^^^^^^^^^^^
    2 | import {Worker} from 'node:worker_threads';
    3 | import crypto from 'node:crypto';

@parcel/resolver-default: Node builtin polyfill "buffer" is not installed, but auto install is disabled.

  /Volumes/Workspace/work/data/parcel-repro/node_modules/crypto-hash/index.js:1:22
  > 1 | import {Buffer} from 'node:buffer';
  >   |                      ^^^^^^^^^^^^^ used here
    2 | import {Worker} from 'node:worker_threads';
    3 | import crypto from 'node:crypto';

  💡 Install the "buffer" package with your package manager, and run Parcel again.
  📝 Learn more

🔦 Context

The dependency uses Conditional exports .

I was able to have the build working by setting an alias:

"alias": {
  "crypto-hash": "crypto-hash/browser"
}

💻 Code Sample

See above

🌍 Your Environment

Software Version(s)
Parcel latest
Node 16.15.1
npm/Yarn npm 8.11.0
Operating System MacOS 12.3.1 on M1
@devongovett
Copy link
Member

Conditional exports are not currently supported. Please see #4155.

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

No branches or pull requests

2 participants