Adding NPM module in React Native Throws Error (unable to resolve module url)

时间:2016-08-31 17:26:13

标签: npm react-native

To be specific I'm using meta-extractor module in react native.

'use strict';
//import React Native
import React, { Component } from 'react';
import {
  Text,
  StyleSheet,
  View,
  TextInput,
  TouchableHighlight, 
} from 'react-native';


var styles = require('../styles/styles');
var metagetplus = require('../../node_modules/meta-extractor');

Here is the error message:

Unable to resolve module url from /Users/name/Desktop/instaldr/node_modules/meta-extractor/index.js: Unable to find this module in its module map or any of the node_modules directories under /Users/node_modules/url and its parent directories This might be related to https://github.com/facebook/react-native/issues/4968

To resolve try the following: 1. Clear watchman watches: watchman watch-del-all. 2. Delete the node_modules folder: rm -rf node_modules && npm install. 3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache.

I tried all suggested resolution methods mentioned in that link, but nothing seems to solve the issue. Can anyone help me out here?

2 个答案:

答案 0 :(得分:0)

导入组件已更改,不应再使用require,请尝试:     从(' meta-extractor')

导入metagetplus

答案 1 :(得分:0)

1。您是否看到过package.json ...如果package.json中没有列出“ meta-extractor”包,它可能会破坏整个系统? 2。尝试使用commonjs require方法:

const metagetplus = require('meta-extractor');

有时模块仅与commonjs require方法一起使用...它可能并非一直与import语句一起使用。软件包“ meta-extractor”已经有一段时间没有更新了,因此可能无法与导入语句一起使用...

所以你能做的就是这个...

1。明确的守望者:watchman watch-del-all 2。清除node_modules:rm -rf node_modules && npm install 3。安装软件包:npm i meta-extractor 4。编辑代码文件:

'use strict';
import React, { Component } from 'react';
import {
  Text,
  StyleSheet,
  View,
  TextInput,
  TouchableHighlight, 
} from 'react-native';


const styles = require('../styles/styles');
const metagetplus = require('meta-extractor');

希望它能起作用...