Can't find variable: PropTypes - reactjs

I am trying some react native code.
Added props for my component based on the instructions given in this blog.
End up in the error, Can't find variable: PropTypes
Found the same question in github but it was closed without any answers
Couldn't get any clues.

You need to do install prop-types with npm install --save prop-types or yarn add prop-types and then add this to your code:
import PropTypes from 'prop-types';

Make sure prop-types is installed:
npm install --save prop-types
Make sure the following line is added in the file where the error originated
import PropTypes from 'prop-types'; .

Ok, so I was having a similar issue when configuring my react router (react-router-dom),
then I realized I used YARN to add react, react-dom and prop-types, and NPM to add the react-router-dom, then I got suspicious it was this the problem and I:
removed it with:
npm uninstall react-router-dom
and installed it with:
yarn add react-router-dom --dev
and it stopped giving me the error / fixed it.

Related

Cannot use MUI 'ContentCopy' icon

I am trying to use the icon 'ContentCopy' from MUI.
https://mui.com/components/material-icons/ says to use the following import:
import ContentCopyIcon from '#mui/icons-material/ContentCopy';
No matter what I do, I get the error:
Module not found: Can't resolve '#mui/icons-material/
I have already tried the following:
npm install #material-ui/core
npm install #material-ui/icons
I also tried deleting my node-modules and re-running npm install.
Any ideas on what else I could try??
It seems that you confused of using version 4 and 5.
You need to install the icons of version 5.
npm install #mui/icons-material
And import the icon from the module.
import ContentCopyIcon from '#mui/icons-material/ContentCopy';
Please refer to this.
to version 5 you need to install mui
npm install #mui/icons-material
mui contains all the icons
from '#mui/icons-material/_';
info https://www.npmjs.com/package/#mui/icons-material

How to use bootstrap-notify in react

i want to use http://bootstrap-notify.remabledesigns.com/ in my react app, i have tried to follow Using bootstrap-notify with Angular 7 but getting error "$.notify is not a function" in console
You need the necessary imports:
import $ from "jquery";
import "bootstrap-notify";
You will need to load them using npm i jquery --save and npm i bootstrap-notify --save. I also had some compiler errors after installing, which I fixed with: (see here)
npm install --save --save-exact react-scripts#3.4.0

Importing react components from private npm repo

I am new to react and have been trying to find my way through. I have created a react component and published it to a private npm repo. so the component is accessed as #myorg/testcomponent.
I did an npm install --save #myorg/testcomponent to install the component into a project created via create-react-app
Inside react, when I do the following, the import fails
import TestComponent from '#myorg/testcomponent'
gives:
Failed to compile.
./src/App.js
Module not found: Can't resolve '#myorg/testcomponent' in '/mnt/c/Workspaces/ui/test_project/src'
I am not sure why it is trying to resolve it from the src directory, while the component is installed in node_modules
how do I get it to resolve from node_modules, is there some step i am missing?

Module not found Error: Can't resolve 'history' in #types/history

Am developing a React Application where I want to use #types/history module..
Installed
npm install --save #types/history
And in my component file trying to import like
import { createBrowserHistory, History } from 'history'
And
import { createBrowserHistory, History } from '#types/history'
But throwing exception like
Module not found: Can't resolve 'history' in
Thanks in advance.
When installing #types/history you are just providing typescript compiler with type information about history package. Not the package itself. See for example this thread for some details.
Therefore - you must install history package in order to use it:
$ npm install --save history
See more info about its usage at their github rep.
try to install history and react router dom package using npm
npm install --save history
npm install react-router-dom --save

Moment in typescript not recognized?

I ran these commands:
npm install tsd -g
tsd install moment --save
it is also injecting into my module but when i am accessing it it is not recognizing moment.
eg.
import * as moment from 'moment';
Could you please help me out.
Try this .
npm install #types/moment --save-dev
It is best to install the typescript definition files as developer dependencies
Then import like this
import * as moment from "moment"

Resources