Skip to content
← Back to activity

Immutable solution version

React Native: package attempted to import node:crypto (0.27.1 regression)

Version 2Sign in to save

Complete solution

Shows how to fix react Native: package attempted to import node:crypto (0.27.1 regression). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Upgrade to replicate@0.29.3 or later instead of pinning 0.26.0. Fixed in 0.29.3 via PR #250.

Steps

  1. replicate-javascript 0.27.1 broke React Native with 'attempted to import node:crypto': a regression where the SDK imported the Node standard library in a code path that runs in React Native (which has no Node stdlib). Fixed in 0.29.3 via PR #250. Upgrade to replicate@0.29.3 or later instead of pinning 0.26.0.
  2. https://github.com/replicate/replicate-javascript/issues/210: Issue replicate/replicate-javascript#210 (closed, 5 comments): When I install version 0.27.1 of replicate-javascript library in react-native project, I get error like below. Node Version: 18.18.0. The package at "node_modules/replicate/lib/util.js" attempted to import the Node standard library module "node:crypto". It failed because the native React runtime does not include the Node standard library. When I install version 0.26.0, it does not give any error. The problem seems to be related to the improvements made in the newly released version 0.27.1.

When to use

You are seeing this: The package at "node_modules/replicate/lib/util.js" attempted to import the Node standard library module "node:crypto". Use this skill when you run into "React Native: package attempted to import node:crypto (0.27.1 regression)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: replicate-javascript 0.27.1, 0.29.3, pinning 0.26.0, 18.18.0. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/replicate/replicate-javascript/issues/210:

Evidence

Issue gh:replicate/replicate-javascript#210: the reporter asked: Issue replicate/replicate-javascript#210 (closed, 5 comments): When I install version 0.27.1 of replicate-javascript library in react-native project, I get error like below. Node Version: 18.18.0. The package at "node_modules/replicate/lib/util.js" attempted to import the Node standard library module "node:crypto". It failed because the native React runtime does not include the Node standard library. When I install version 0.26.0, it does not give any error. The problem seems to be related to the improvements made in the newly released version 0.27.1. The verified answer was: replicate-javascript 0.27.1 broke React Native with 'attempted to import node:crypto': a regression where the SDK imported the Node standard library in a code path that runs in React Native (which has no Node stdlib). Fixed in 0.29.3 via PR #250. Upgrade to replicate@0.29.3 or later instead of pinning 0.26.0. Evidence thread: https://github.com/replicate/replicate-javascript/issues/210

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_t85hSovSZckpgDaGisEdZA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">React Native: package attempted to import node:crypto (0.27.1 regression) <span>— Vectle</span></a>

React Native: package attempted to import node:crypto (0.27.1 regression) | Vectle