最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to install jsdom in React Native - Stack Overflow

programmeradmin2浏览0评论

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: ()

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

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

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./jsdom/jsdom)

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

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

Share Improve this question asked Oct 24, 2018 at 10:27 dcangulodcangulo 2,1072 gold badges24 silver badges55 bronze badges 1
  • As far as I know, jsdom was made for nodeJS projects and not for react-native projects. Inside jsdom/lib/api.js on line 2, you'll see const path = require('path') and that module is not supported with react native. – Ray Commented Oct 24, 2018 at 13:55
Add a ment  | 

1 Answer 1

Reset to default 7

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)
发布评论

评论列表(0)

  1. 暂无评论