Router: Yarn Install Fails - Undici@7.5.0 Requires Node.js >= 20.18.1 (Current: 18.18.0)

by ADMIN 89 views

Router: Yarn Install Fails - undici@7.5.0 Requires Node.js >= 20.18.1 (Current: 18.18.0)

Problem

Running yarn install in a project using Expo Router fails due to an incompatible version of the undici package. Specifically, undici@7.5.0, a dependency of Expo Router, requires Node.js version 20.18.1 or higher. However, the current Node.js version of the Expo build environment is 18.18.0.

Steps to Reproduce

  1. Clone the provided minimal reproducible project.
  2. Navigate to the project directory in your terminal.
  3. Execute yarn install.

Expected Behavior

yarn install should complete successfully without errors.

Actual Behavior

yarn install fails with the following error message

error undici@7.5.0: The engine "node" is incompatible with this module. Expected version ">=20.18.1". Got "18.18.0"
error Found incompatible module.

Additional Information

  • Using npm install does not produce this error.

Environment

expo-env-info 1.2.2 environment info:
    System:
      OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
      Shell: 5.1.16 - /bin/bash
    Binaries:
      Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
    IDEs:
      Android Studio: AI-221.6008.13.2211.9619390
    Expo Workflow: managed

Solution

To resolve this issue, you need to upgrade your Node.js version to 20.18.1 or higher. Here are the steps to follow:

Step 1: Check the current Node.js version

You can check the current Node.js version by running the following command in your terminal:

node -v

This will display the current version of Node.js installed on your system.

Step 2: Upgrade Node.js to the required version

You can upgrade Node.js to the required version using the following command:

nvm install 20.18.1

This will download and install Node.js version 20.18.1.

Step 3: Verify the upgraded Node.js version

After upgrading Node.js, you can verify the new version by running the following command:

node -v

This should display the upgraded version of Node.js, which is 20.18.1 or higher.

Step 4: Re-run yarn install

Once you have upgraded Node.js to the required version, you can re-run yarn install to install the dependencies:

yarn install

This should complete successfully without errors.

Conclusion

In this article, we have discussed the issue of yarn install failing due to an incompatible version of the undici package. We have also provided a solution to upgrade Node.js to the required version and re-run yarn install to install the dependencies successfully.

Minimal Reproducible Example

You can find a minimal reproducible example of this issue on GitHub:

https://github.com/Dosbodoke/minimal-expo-router-error

Which Package Manager are You Using?

We are using Yarn as the package manager.

If the Issue is Web-Related, Please Select the Bundler

We are not using a bundler in this case.

Summary

In summary, this article has discussed the issue of yarn install failing due to an incompatible version of the undici package. We have also provided a solution to upgrade Node.js to the required version and re-run yarn install to install the dependencies successfully.
Router: Yarn Install Fails - undici@7.5.0 Requires Node.js >= 20.18.1 (Current: 18.18.0) - Q&A

Q: What is the issue with yarn install in a project using Expo Router?

A: The issue is that yarn install fails due to an incompatible version of the undici package. Specifically, undici@7.5.0, a dependency of Expo Router, requires Node.js version 20.18.1 or higher. However, the current Node.js version of the Expo build environment is 18.18.0.

Q: What is the error message displayed when yarn install fails?

A: The error message displayed when yarn install fails is:

error undici@7.5.0: The engine "node" is incompatible with this module. Expected version ">=20.18.1". Got "18.18.0"
error Found incompatible module.

Q: Why does npm install not produce this error?

A: npm install does not produce this error because it uses a different version of the undici package that is compatible with the current Node.js version.

Q: How can I resolve this issue?

A: To resolve this issue, you need to upgrade your Node.js version to 20.18.1 or higher. You can do this by running the following command:

nvm install 20.18.1

Q: What is the minimum Node.js version required for Expo Router?

A: The minimum Node.js version required for Expo Router is 20.18.1.

Q: Can I use a lower version of Node.js with Expo Router?

A: No, you cannot use a lower version of Node.js with Expo Router. The undici package requires Node.js version 20.18.1 or higher, and using a lower version will result in the error message displayed above.

Q: How can I verify that I have upgraded Node.js to the required version?

A: You can verify that you have upgraded Node.js to the required version by running the following command:

node -v

This should display the upgraded version of Node.js, which is 20.18.1 or higher.

Q: What if I am using a different package manager, such as npm?

A: If you are using a different package manager, such as npm, you may not experience this issue. However, if you are using Yarn, you will need to upgrade Node.js to the required version to resolve the issue.

Q: Can I use a different version of the undici package?

A: No, you cannot use a different version of the undici package. The undici package is a dependency of Expo Router, and using a different version will result in compatibility issues.

Q: How can I prevent this issue in the future?

A: To prevent this issue in the future, you can ensure that you are using the latest version of Node.js and the required version of the undici package. You can also use a package manager like npm, which may not experience this issue.

Q: What if I am using a managed workflow with Expo?

A: If you are using a managed workflow with Expo, you may not need to upgrade Node.js to the required version. However, if you are using a bare workflow, you will need to upgrade Node.js to the required version to resolve the issue.

Q: Can I use a different version of Expo Router?

A: No, you cannot use a different version of Expo Router. The undici package is a dependency of Expo Router, and using a different version will result in compatibility issues.

Q: How can I get help with this issue?

A: You can get help with this issue by reaching out to the Expo community, checking the Expo documentation, or seeking help from a developer who has experience with Expo Router.