Node standard library module "url". It failed because React Native does not include the Node standard library.

The package at "node_modules/particle-api-js/lib/EventStream.js" 
attempted to import the Node standard library module "url". 
It failed because React Native does not include the Node standard library. 
Read more at https://docs.expo.io/versions/latest/introduction/faq/#can-i-use-nodejs-packages-with-expo

Maybe I’m reading this wrong but in the link to the expo docs it says

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.

It is complaining about ‘url’ but the docs say that it should work.

I also tried to nmp install url

  "dependencies": {
    "expo": "^32.0.0",
    "particle-api-js": "^7.4.0",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "url": "^0.11.0"
  },

But that didn’t do the trick

2 Likes

@norfeldtconsulting Hi, Did you find the solution for this. IM getting this after installing ‘got’ request

This works fine for me:

$ expo init -t blank url-test
$ cd url-test
$ expo install url

With this code in App.js:

import React from 'react';
import { Text, View } from 'react-native';
import url from 'url';

export default function App() {
  const { hostname, protocol, port, path } = url.parse(
    'http://www.example.com/some/path.html'
  );
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Host: {hostname}</Text>
      <Text>Protocol: {protocol}</Text>
      <Text>Port: {port}</Text>
      <Text>Path: {path}</Text>
    </View>
  );
}

If I try using got I get the following:

The package at "node_modules/got/dist/source/as-promise/index.js" attempted to import the Node standard library module "events". It failed because the native React runtime does not include the Node standard library. Read more at https://docs.expo.io/workflow/using-libraries/#using-third-party-libraries

undefined Unable to resolve module `events` from `node_modules/got/dist/source/as-promise/index.js`: events could not be found within the project.

I think you’re out of luck with events. Maybe see if Ky works for you?