Last updated: Apr 7, 2024
Reading timeยท3 min
To solve the TypeError: Cannot read properties of undefined (reading 'transformFile'):
react-native
version to the latest.NODE_OPTIONS
environment variable to --openssl-legacy-provider
.Metro has encountered an error: TypeError: Cannot read properties of undefined (reading 'transformFile') at Bundler.transformFile (/Users/bobbyhadz/node_modules/metro/src/Bundler.js:48:30) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5)
react-native
, the error is caused because of incompatibility between older versions of Metro with newer versions of Node.js.The issue has been resolved in newer versions of react-native.
Try to delete your node_modules
and
package-lock.json (not
package.json
) files and rerun the npm install
command.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean your npm cache npm cache clean --force npm install
Open your terminal in your project's root directory and run the following
command to upgrade react-native
.
npx react-native upgrade
If the issue persists after upgrading react-native, set the NODE_OPTIONS
environment variable to --openssl-legacy-provider
.
NODE_OPTIONS
environment variableOpen your terminal and run the specific command for your shell type.
# ๐๏ธ for macOS, Linux or Windows Git Bash export NODE_OPTIONS=--openssl-legacy-provider # ---------------------------------------------------- # ๐๏ธ for Windows CMD (Command Prompt) set NODE_OPTIONS=--openssl-legacy-provider # ---------------------------------------------------- # ๐๏ธ for Windows PowerShell $env:NODE_OPTIONS="--openssl-legacy-provider" # ---------------------------------------------------- # ๐๏ธ for Docker (in your Dockerfile) ENV NODE_OPTIONS="--openssl-legacy-provider"
The --openssl-legacy-provider
option is needed when using the latest version
of Node.js, because
Node.js 17 and later uses OpenSSL 3.0
which has had some breaking changes.
NODE_OPTIONS
environment variable helped, you don't have to make any of the following changes.If the error persists, try using the --openssl-legacy-provider
flag when
issuing the command in your package.json
file.
First install the cross-env
package to make the command work on macOS, Linux
and Windows.
npm install cross-env
Here is an example.
{ "scripts": { "start": "cross-env NODE_OPTIONS=--openssl-legacy-provider && expo start", } }
Simply add NODE_OPTIONS=--openssl-legacy-provider
to your command.
Make sure to update the part after
cross-env NODE_OPTIONS=--openssl-legacy-provider &&
if you have to.
If you get an error that "node: --openssl-legacy-provider is not allowed in
NODE_OPTIONS", unset the NODE_OPTIONS
environment variable and rerun the
command.
# ๐๏ธ for macOS, Linux or Windows Git Bash unset NODE_OPTIONS # ----------------------------------------- # ๐๏ธ for Windows CMD (Command Prompt) set NODE_OPTIONS= # ----------------------------------------- # ๐๏ธ for Windows PowerShell [Environment]::SetEnvironmentVariable('NODE_OPTIONS', '', 'User') [Environment]::SetEnvironmentVariable('NODE_OPTIONS', '', 'Machine')
Try to rerun your script after deleting the environment variable.
If none of the suggestions helped, you can downgrade your Node.js version to 16.13.0 to resolve the error.
You can issue the following command to downgrade your Node.js version to
16.13.0
if you use NVM.
nvm install 16 nvm use 16
The error often occurs when installing Node.js version 17+. Rolling back to version 16.X.X solves it.
The --openssl-legacy-provider
option is needed when using the latest version
of Node.js, because
Node.js 17 and later uses OpenSSL 3.0
which has had some breaking changes.
Dockerfile
.If you still get the error after downgrading to Node version 16, try to delete
your node_modules
and
package-lock.json, rerun the
npm install
command and restart your development server.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean your npm cache npm cache clean --force npm install
Restart your development server after issuing the npm install
command.
click on the article and follow the instructions.
You can learn more about the related topics by checking out the following tutorials: