简体   繁体   中英

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. For my current project, I had installed react-native using

npm install react-native

This also reflects in my package.json and node_modules folder

"react-native": "^0.61.5"

Now, when I try to import react-native as follows into 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 cannot make out if this is a bug in npm or if there is a lack of understanding for installing packages on my side. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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