首页 > 解决方案 > 无法在我的项目中解析“react-native”

问题描述

我从 React 官方网站制作了教程小项目,当我尝试使用一些本机反应组件(如 Text 和 ImageBackground)时,我得到以下编译错误:

未找到模块:无法在...中解析“react-native”

我用“npx create-react-app”创建了我的项目。

我所做的导入。

import { Text, ImageBackground } from 'react-native'

我尝试做 npm install 和 npm install 'react-native-elements' 等等......没有任何效果。

无论如何,这是我的 package.json:

{
  "name": "tutorial",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

有任何想法吗?

标签: reactjsreact-native

解决方案


对于 React Native 移动应用程序

使用此命令创建 react 原生项目 android 和 ios 应用程序。

npx react-native init AwesomeProject

你还需要一些其他配置来运行这个项目,比如 node.js、android studio、android sdk 和 xcode for ios。您可以点击此链接了解更多详情。

https://facebook.github.io/react-native/docs/getting-started

对于 React Web 应用程序

npx create-react-app上面的命令用于响应本机 Web 应用程序。


推荐阅读