【问题标题】:Unable to resolve module `react`无法解析模块`react`
【发布时间】:2018-03-05 01:45:32
【问题描述】:

我克隆了https://github.com/oblador/react-native-progress

在示例文件夹上:

npm i

react-native run-ios

但我遇到了错误,这是错误截图链接:Unable to resolve module react

这是代码:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
  Animated,
  Easing,
  View,
  ViewPropTypes,
} from 'react-native';

为什么我的react模块不能解析,而react native模块可以?

【问题讨论】:

    标签: node.js reactjs react-native node-modules


    【解决方案1】:

    示例在package.json 文件中构建节点依赖项时出错

     "dependencies": {
        "react": "16.0.0-alpha.12",
        "react-native": "0.47.2",
        "react-native-progress": "file:../" // error
      },
    

    解决这个问题

    1. 在 Example 文件夹中运行 npm uninstall react-native-progress
    2. 卸载后运行npm install react-native-progress --save

    然后正常运行您的示例应用

    【讨论】:

    • 但是为什么https://github.com/react-community/react-native-image-picker/blob/develop/Example/package.json 可以运行成功?
    • react-native-progress 有依赖关系,所以它会在 node_modules 中搜索,但它会混淆节点 node_modules 文件夹在哪里 react-native-image-picker 没有依赖关系,所以它会顺利运行
    猜你喜欢
    • 2017-10-11
    • 2017-07-23
    • 2016-03-23
    • 1970-01-01
    • 2018-11-18
    • 2020-04-15
    • 2020-03-02
    • 2016-12-27
    • 2017-12-21
    相关资源
    最近更新 更多