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

Remix v1.16.0 - Unable to build app with crypto dependency #6284

Closed
1 task done
nggonzalez opened this issue May 2, 2023 · 10 comments
Closed
1 task done

Remix v1.16.0 - Unable to build app with crypto dependency #6284

nggonzalez opened this issue May 2, 2023 · 10 comments

Comments

@nggonzalez
Copy link

What version of Remix are you using?

v1.16.0

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

  1. Create an app with import { createHash } from "crypto".
  2. Build the app

Expected Behavior

Should build successful - behavior in 1.15.0

Actual Behavior

Fails to build

✘ [ERROR] No matching export in "node_modules/@remix-run/dev/node_modules/esbuild-plugin-polyfill-node/polyfills/empty.js" for import "createHash"

    node_modules/@taskforcesh/bullmq-pro/node_modules/bullmq/dist/esm/classes/repeat.js:3:9:
      3 │ import { createHash } from 'crypto';
@SleeplessByte
Copy link

Happens for all imports from crypto. It seems that remix is trying to "polyfill" them, but the polyfill for that package doesn't exist.

@nggonzalez nggonzalez changed the title Remix v1.16.0 - Unable to build app with crypto.createHash dependency Remix v1.16.0 - Unable to build app with crypto dependency May 2, 2023
@nggonzalez
Copy link
Author

Updated the title to make that clear.

I think the compiler config likely changed between v1.15.0 and v1.16.0.

@pcattori
Copy link
Contributor

pcattori commented May 2, 2023

Probably related to #5274 and #6259

@tmcw
Copy link
Contributor

tmcw commented May 23, 2023

This also causes issues with importing the TypeScript "ts" package from frontend code - the injected polyfills make the browser environment look enough like Node that TypeScript tries to run in Node with FS access. It'd be great to avoid Node polyfills altogether in the web builds.

@MichaelDeBoey
Copy link
Member

We just published version 1.17.1-pre.0 which includes #6562 (a possible fix). If you'd like to take it for a test run please try it out and let us know what you think!

@fiws
Copy link

fiws commented Jun 9, 2023

I think 1.17.1-pre.0 almost works, but it still fails if we try to import randomUUID.

✘ [ERROR] No matching export in "node-modules-polyfills:crypto" for import "randomUUID"

@marcfalk
Copy link

marcfalk commented Jun 14, 2023

I think 1.17.1-pre.0 almost works, but it still fails if we try to import randomUUID.

✘ [ERROR] No matching export in "node-modules-polyfills:crypto" for import "randomUUID"

@MichaelDeBoey Can confirm that the error still throws. I'm using Remix 1.17.1-pre.0 and @defer/client@1.4.0, which relies on randomUUID from crypto.

@imranbarbhuiya
Copy link

I think 1.17.1-pre.0 almost works, but it still fails if we try to import randomUUID.

✘ [ERROR] No matching export in "node-modules-polyfills:crypto" for import "randomUUID"

@MichaelDeBoey Can confirm that the error still throws. I'm using Remix 1.17.1-pre.0 and @defer/client@1.4.0, which relies on randomUUID from crypto.

defer-run/defer.client#60 (comment)

@luisgrisolia
Copy link

Changing to a namespace import fixed the issue
import * as crypto from "crypto";
let random_uuid = crypto.randomUUID()

Package:
"@remix-run/dev": "^1.18.1"

@brophdawg11 brophdawg11 added this to v2 Aug 3, 2023
@brophdawg11 brophdawg11 moved this to Backlog in v2 Aug 3, 2023
@pcattori pcattori assigned markdalgleish and unassigned pcattori Aug 7, 2023
@markdalgleish
Copy link
Member

markdalgleish commented Aug 9, 2023

I've confirmed that import { createHash } from "crypto" works in the latest version of Remix.

As @luisgrisolia mentioned, you may have to use import * if you're using an export that isn't polyfilled in the client build.

@markdalgleish markdalgleish moved this from Backlog to Closed in v2 Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Closed
Development

No branches or pull requests