71

I have updated node today and I'm getting this error:

error: TypeError: Cannot read properties of undefined (reading 'transformFile')
    at Bundler.transformFile (/Users/.../node_modules/metro/src/Bundler.js:48:30)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.transform (/Users/.../node_modules/metro/src/lib/transformHelpers.js:101:12)
    at async processModule (/Users/.../node_modules/metro/src/DeltaBundler/traverseDependencies.js:137:18)
    at async traverseDependenciesForSingleFile (/Users/.../node_modules/metro/src/DeltaBundler/traverseDependencies.js:131:3)
    at async Promise.all (index 0)
    at async initialTraverseDependencies (/Users/.../node_modules/metro/src/DeltaBundler/traverseDependencies.js:114:3)
    at async DeltaCalculator._getChangedDependencies (/Users/.../node_modules/metro/src/DeltaBundler/DeltaCalculator.js:164:25)
    at async DeltaCalculator.getDelta (/Users/.../node_modules/metro/src/DeltaBundler/DeltaCalculator.js:94:16)

Other than that I haven't done anything unusual, so I'm not sure what to share. If I'm missing any info please comment and I'll add it.

While building the terminal also throws this error:

Failed to construct transformer:  Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at stableHash (/Users/.../node_modules/metro-cache/src/stableHash.js:19:8)
    at Object.getCacheKey (/Users/.../node_modules/metro-transform-worker/src/index.js:593:7)
    at getTransformCacheKey (/Users/.../node_modules/metro/src/DeltaBundler/getTransformCacheKey.js:24:19)
    at new Transformer (/Users/.../node_modules/metro/src/DeltaBundler/Transformer.js:48:9)
    at /Users/.../node_modules/metro/src/Bundler.js:22:29
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

My node, npx and react-native versions are:

  • node: 17.0.0
  • npx: 8.1.0
  • react-native-cli: 2.0.1
gkpo
  • 2,623
  • 2
  • 28
  • 47
Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116

19 Answers19

92

Ran into the same issue with Node.js 17.0.0. To solve it, I downgraded to version 14.18.1, deleted node_modules and reinstalled.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
memoalv
  • 1,052
  • 8
  • 5
  • 1
    After 3 days trying to find the issue, this did the job. I reinstalled the node LTS 14.8.1, and it solved the problem. Thanks – Edi Oct 20 '21 at 16:56
  • 3
    It worked! Just remind that you've to delete node_modules and install it again using npm/yarn install – Erick Gutierrez Oct 21 '21 at 15:03
  • 2
    Is 14.8.1 the highest for which it works ? seems like a big step back to go back 3 versions... – gkpo Dec 27 '21 at 10:37
  • 1
    I haven't tested it but according to other people in the thread version 16.13.0 is the latest version that will work fine – memoalv Dec 27 '21 at 22:24
  • 1
    `nvm install 14.18.1` and even on an M1 Mac, this takes long enough to go on a coffee break, so consider going on a coffee break after running that command. – Karatekid430 Jan 27 '22 at 04:18
  • Anyboday has the idea why its happening with node 17+? I downgraded from 17.3.0 to node 16.3.0 and it started working. – Adnan Ali May 31 '22 at 16:08
  • So, I didn't understand why this was the solution and started digging into work arounds. It's because Node 17+ isn't a Long Term Support (LTS) version. Node only uses even numbers for LTS. So, while 17 is the *latest* version, it doesn't mean it's the most bulletproof. There are some workarounds as this has to do with how Node 17 is working with features that are deprecated by OpenSSL, but the tried and true is to go to the most recent LTS version of Node. Lesson learned on my end! – trevorhpittman Jun 20 '22 at 18:51
  • I needed to downgrade node and also delete Xcode's DerivedData. – hetelek Aug 03 '22 at 23:35
  • For my project i have install the node 16 and it works – Sachin Saini Feb 06 '23 at 06:11
  • Not worked for me :( – Aman Deep Mar 30 '23 at 13:35
39

you can resolve it by downgrading the node js

> nvm list // to see all available node version

> nvm install 16.13.0 // to install the version I wanted 

> nvm use 16.13.0  // use the installed version 
OR
> nvm alias default 16 // use the installed version as DEFAULT 
uzai sindiko
  • 561
  • 4
  • 6
  • I do the above steps and everything is fine. But when I try to build, it fails again. And if I close the terminal, and then I check again node version, it says 17?! – Fotios Tsakiris Jan 14 '22 at 09:30
  • @FotiosTsakiris if you want your node version to persist, you can use ```nvm alias default 16.13.0```, that way your node version always stay at version 16. – uzai sindiko Jan 15 '22 at 11:38
  • 1
    Thanks a lot for the comment. Actually, I tried something else and it worked. After I set `nvm use 16.13.0` I did `nvm uninstall 17.3.1` and then the project did build. – Fotios Tsakiris Jan 15 '22 at 15:43
  • I also facing the same issue. I installed the latest version of node 18.12.0 but It's not working. So I have downgraded node version 16.13.0 and it's working fine for me. – immodi Nov 16 '22 at 15:17
8

I tried different node versions...same error. Uninstalled and tried new versions of Android Studio...same error. Started brand new projects from scratch...same error. Deleted node_modules and ran npm i...same error.

Here's what did work for me.

Run

npx react-native info

Towards the top of that readout, it should say what Node version you are using. (it told me I was using Node: 17.xx.x in a stray node_modules folder.)

My fix was simply renaming that folder(in case deleting it breaks a different project). Now when I run npx react-native info it tells me the correct node version(16.13.1) and all my projects are running in the emulator again!

Trithir
  • 81
  • 1
  • 1
5

This issue is due to the difference between node version you are currently using for example node version 19 and node version used by the project.

To Solve this issue you need to downgrade or upgrade according to the node version used by project and your current node version.

you have to install node first and then then install nvm (NODE VERSION MANAGER). nvm is a node version manager with which you can install multiple node version

CURRENT LTS OLD STABLE OLD UNSTABLE
19.2.0 18.12.1 0.12.18 0.11.16
19.1.0 18.12.0 0.12.17 0.11.15
19.0.1 16.18.1 0.12.16 0.11.14
19.0.0 16.18.0 0.12.15 0.11.13
18.11.0 16.17.1 0.12.14 0.11.12
18.10.0 16.17.0 0.12.13 0.11.11
18.9.1 16.16.0 0.12.12 0.11.10
18.9.0 16.15.1 0.12.11 0.11.9
18.8.0 16.15.0 0.12.10 0.11.8
18.7.0 16.14.2 0.12.9 0.11.7
18.6.0 16.14.1 0.12.8 0.11.6
18.5.0 16.14.0 0.12.7 0.11.5
18.4.0 16.13.2 0.12.6 0.11.4
18.3.0 16.13.1 0.12.5 0.11.3
18.2.0 16.13.0 0.12.4 0.11.2
18.1.0 14.21.1 0.12.3 0.11.1
18.0.0 14.21.0 0.12.2 0.11.0
17.9.1 14.20.1 0.12.1 0.9.12
17.9.0 14.20.0 0.12.0 0.9.11
17.8.0 14.19.3 0.10.48 0.9.10

To Install nvm please follow this Link

After this you can use the following nvm commands

nvm ls

// install specific version of node
nvm install 6.9.2

// set default version of node
nvm alias default 6.9.2

// switch version of node
nvm use 6.9.1
Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47
  • this is the most amazing and helpful answer. I was trying for three days and now my issue is resolved. thank you so much – hamid Jan 11 '23 at 06:03
4

I am using Expo CLI with Node.js 17 and encountered the same error, and found the hint to the resolution (without downgrading Node.js) from here: https://github.com/facebook/react-native/issues/33107#issuecomment-1042612307

However, instead of using export I installed cross-env as devDependency by running the following command: npm i --save-dev cross-env

Then I added the following command against start script in package.json under scripts section.

"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider expo start"

Umair Malhi
  • 565
  • 1
  • 5
  • 16
  • 2
    This sounds like it's specifically for M1 Macs, based on the details I see in the link. Just labeling it here in case someone with a non-M1 expects it to solve their problem. – Dom Ramirez Jul 25 '22 at 20:21
2

Quick and dirty workaround (worked for me):

Add or update your package.json engines section with something like this to stop trying to build with Node 17.0.x Current, until you resolve the new OpenSSL PKCS8 format in the tls module:

  "engines": {
    "node": "<17",
    "npm": "<8.2"
  },
Georgi Marinov
  • 91
  • 1
  • 3
  • 5
2

First, you have to install the node version manager:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

or:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

after installation, (if you are on Linux, close and reopen your terminal and) test it:

nvm -v

then install the node version 16.3.0:

nvm install 16.13.0

and ask the nvm to use this version:

nvm use 16.13.0
2

The error comes from the node version. So, you will need to downgrade.

npx react-native info - // to see what node version your project uses.

nvm list // to see all available node version

nvm install 16.18.0 // to install the version you want

nvm use 16.18.0  // use the installed version

OR

nvm alias default 16 // use the installed version as DEFAULT
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
2

Run:

export NODE_OPTIONS=--openssl-legacy-provider

To make connection to openssl

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Arun sankar S
  • 141
  • 1
  • 3
1

I experienced the same issue. Seems that the problem is due to version 17.x of Node.js. I solved downgrading to Node.js 16.12.0.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
1

had the same issue. downgrade to version 16.13.1 from 17.3.0 and it worked great.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30700325) – CodeChanger Jan 03 '22 at 11:39
1

check your node version first using nvm list uninstall the unnecessary version of node using nvm uninstall version change the version with the version number which is in use. install the new version of node using nvm install version_number use the installed version of node using nvm use version_number . Replace version_number with the version of node you have installed.

Meet Shah
  • 21
  • 6
1

In case, you do the steps of @uzai sindiko and when you try to build, it fails again. And if you close the terminal, and then you check again node version, it says 17.3.1.

Then after you set nvm use 16.13.0 do also nvm uninstall 17.3.1 and then your project will be build.

Thanks

Fotios Tsakiris
  • 1,310
  • 1
  • 18
  • 24
1

If you use an older osx version, you may need to add an nvm script to your zshrc file. Here is how to do so:

  • in your terminal, type open ~/.zshrc
  • in your .zshrc file, copy paste the following code:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  • go back to your terminal and run source ~/.zshrc

Now nvm will work.

DoneDeal0
  • 5,273
  • 13
  • 55
  • 114
1
  1. Use node version 16.12.0. If you are using nvm, set default node version to 16.12.0. You can use following command
nvm alias default 16.12.0
  1. Remove node_modules folder. You can use following command:
rm -rf node_modules 
  1. Run the android run command again
Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
1

Just throwing this out there. If you use watchFolders in metro.config.js, make sure you remove that key before building! That fixed it for me. It's useful if you are npm linking other packages but obviously eas build will not be able to find those links.

Herman
  • 242
  • 1
  • 2
  • 10
0

Solution which works for me. Try to generate your main.jsbundle file with the below react-native command and verify it in your iOS folder.

1)Delete your pods folder and Podfile.lock file

2)run command

react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'

3)After that run below command

npm start -- --reset-cache
civani mahida
  • 314
  • 3
  • 8
0

Your metro might be probably running somehow. Restart you computer before trying anything fancy

-8

I tried every solution on the internet but none of them helped, check if nothing's working then you must be having nodejs and node in your system. You can check on your terminal with node -v and nodejs -v

Uninstall nodejs

sudo apt-get uninstall nodejs

and you're good to go!