我从npm转移到yarn上,由于某种原因,尽管我导入了无法识别它的react-native库,但出现了错误:
./src/App.js
Module not found: Can't resolve 'react-native' in '/var/react-projects/gymgains/src'
我删除了package.json.lock,也删除了yarn.lock,然后重试:
yarn
但是它并没有解决问题。
这是我的package.json:
{
"name": "App",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-firebase-file-uploader": "^2.4.2",
"react-native": "^0.58.5",
"react-native-cli": "^2.0.1",
"react-scripts": "2.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
这是我的导入语句:
import React, { Component } from 'react';
import firebase from 'firebase';
import { Text, View, Image } from 'react-native';
import 'firebase/firestore';
import FileUploader from 'react-firebase-file-uploader';
使用“ yarn start”运行它以在浏览器中看到它,然后将其推送到Android以在模拟器中对其进行测试之间是否有区别,这可能是react-native在Web浏览器中不起作用的问题? 知道如何解决这个问题吗?
谢谢
答案 0 :(得分:0)
您可以尝试npm install
看看吗?我认为您的node_modules没有react-native
软件包。
答案 1 :(得分:0)
我有一些非常相似的问题:
未找到模块:无法解析“ react-native”
对我而言,它帮助我做到了
yarn add react-native-web
因为您没有安装该模块。您可以尝试一下。