Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install jsdom in React Native

Steps to reproduce:

  1. react-native init myproject.
  2. cd myproject.
  3. npm install jsdom.
  4. In my App.js, I added import jsdom from 'jsdom';.
  5. react-native run-ios.

Expected Output: App starts on the React native landing page.

Actual Output: Unable to resolve module path from /Users/davidangulo/Desktop/mobile/myproject/node_modules/jsdom/lib/api.js: Module path does not exist in the Haste module map

According to their readme: (https://github.com/jsdom/jsdom)

const jsdom = require("jsdom");
const { JSDOM } = jsdom;

That is how you initialize it but unfortunately, it doesn't work.

like image 478
dcangulo Avatar asked Sep 13 '25 22:09

dcangulo


1 Answers

Hey I had the same problem with jsdom and react-native, jsdom is made for node which would include path, fs and more, but react-native does not have all this.

For me jsdom-jscore did the trick:

import { jsdom } from 'jsdom-jscore-rn'

// ...

const dom = jsdom(html)
like image 84
Vl4dimyr Avatar answered Sep 16 '25 13:09

Vl4dimyr