简体   繁体   English

react-native:通过npm安装后无法导入react-native

[英]react-native:Unable to import react-native after installing through npm

I am in my initial stages of learning react and have a limited understanding of npm manager and importing libraries into project.我正处于学习 React 的初始阶段,对 npm 管理器和将库导入项目的理解有限。 For my current project, I had installed react-native using对于我当前的项目,我使用安装了 react-native

npm install react-native

This also reflects in my package.json and node_modules folder这也反映在我的 package.json 和 node_modules 文件夹中

"react-native": "^0.61.5"

Now, when I try to import react-native as follows into AppCarousel.js现在,当我尝试将 react-native 如下导入 AppCarousel.js 时

import React from 'react';
import {Dimensions} from 'react-native';

and then build the application , i get the following error message然后构建应用程序,我收到以下错误消息

.\src\Components\AppCarousel.js
Cannot find module: 'react-native'. Make sure this package is installed.

You can install this package by running: npm install react-native.


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react@1.0.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\{USER}\AppData\Roaming\npm-cache\_logs\2020-01-09T13_08_54_364Z-debug.log
The terminal process terminated with exit code: 1

I tried referring to the the following questions i) link1 ii) link2我尝试参考以下问题 i) link1 ii) link2

I cannot make out if this is a bug in npm or if there is a lack of understanding for installing packages on my side.我无法确定这是 npm 中的错误还是我对安装软件包缺乏了解。 Any help will be appreciated, thanks.任何帮助将不胜感激,谢谢。

Terminal to kill the process:终止进程的终端:

ps -ax | grep npm

Then try to navigate to your directory in your terminal and try to do write this:然后尝试导航到终端中的目录并尝试编写以下内容:

npm I react

or again:或再次:

npm i react-native

Simple explanation to get in use with TypeScript and React: https://facebook.github.io/react-native/docs/typescript使用 TypeScript 和 React 的简单解释: https : //facebook.github.io/react-native/docs/typescript

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM