Can I use Node.js packages with Expo?

This is a frequently asked question, so here is the answer!

If the package depends on Node standard library APIs, you will not be able to use it with Expo. The Node standard library is a set of functionality implemented largely in C++ that exposes functions to JavaScript that aren’t part of the JavaScript language specification, such as the ability to read and write to your filesystem. React Native, and by extension Expo, do not include the Node standard library, just like Chrome and Firefox do not include it. JavaScript is a language that is used in many contexts, from mobile apps (in our case), to servers, and of course on websites. These contexts all include their own runtime environments that expose different APIs to JavaScript, depending on what makes sense in the context.

As a side note, some Node standard library APIs do not depend on C++ extensions but instead can be implemented directly in JavaScript, such as url and assert. If a package you wish to use only depends on these Node APIs, you can install them from npm and the package will work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.