Weirdly, the react-native-vector-icons was working well but by using ^ ("^6.6.0") for its version in the package.json file on the new release this error happens.
It's weird because two days ago it works well but now starting of my project ran to this error:
error: Error: Unable to resolve module #react-native-community/toolbar-android from node_modules\react-native-vector-icons\lib\toolbar-android.js: #react-native-community/toolbar-android could not be found within the project.
After reading this issue and trying many solutions I reach to two solutions:
You can delete all node_modules folder and put the version of react-native-vector-icons to "6.6.0" instead of "^6.6.0" and then install all packages again. absolutely, it is better to delete all caches and builds and start everything again. (NOT Recommended)
You can install the #react-native-community/toolbar-android by using the below command:
yarn add #react-native-community/toolbar-android
Or
npm install --save #react-native-community/toolbar-android
Note: Both of these solutions are temporary and soonly this bug will be fixed and there is no need to install the toolbar-android package.
Prev Update
I update the package to the version "^7.0.0" on my project and still, the issue is remaining, so this solution is currently perseverance.
New Update
this issue is fixed on version "^7.1.0" and there is no need to install the #react-native-community/toolbar-android.
Update the library
react-native-vector-icons
to the latest version.
I had this problem too.
In my case, only works when I removed and added the package again with the latest version (7.0.0).
yarn remove react-native-vector-icons
yarn add react-native-vector-icons
Had this EXACT same error. All I had to do was install toolbar-android & voilĂ !
npm install --save #react-native-community/toolbar-android
Go the path \node_modules\native-base\node_modules\react-native-vector-icons\lib\toolbar-android.js
Replace import ToolbarAndroid from '#react-native-community/toolbar-android' to import {ToolbarAndroid} from './react-native';
I also got the same error after upgrading from version 6 to 7. The issue can be fixed simply by resetting the cache.
Please try npm start -- --reset-cache
do this:
rm -rf node_modules/
rm -rf package.lock.json
npm i
react-native start --reset-cache
from your project directory:)
Just Import it direct from react native it solves my problem
node_modules\react-native-vector-icons\lib\toolbar-android.js
import { ToolbarAndroid } from 'react-native';
Same issue, I solved it:
My environment:
RN: 0.61.5
Node: v12.18.3
OS: Windows 10 Pro
You can install react-native-vector-icons latest version (current 7.0.0).
And do not run auto-link (react-native link react-native-vector-icons)
Finally, running react-native start --reset-cache
Good luck.
First let's understand the standard convention used in package.json for packege's version.
So if you see ~1.0.2 it means to install version 1.0.2 or the latest patch version such as 1.0.4. If you see ^1.0.2 it means to install version 1.0.2 or the latest minor or patch version such as 1.1.0.
Now, coming to the issue.
The issue is caused because you are having a version of react-native-vector-icons which is giving you some trouble.
Check it's version by this command under your project directory:
npm list react-native-vector-icons --version \ is it 6.6.0 ??
No ?? . There is the problem. You need strictly 6.6.0 but you got something else.
Solution:
Delete node_modules directory under your project. Change the version of react-native-vector-icons in package.json to 6.6.0 (basically remove ^ to tell npm to get me exactly what I want. Nothing more, nothing less !)
Then do npm install !
The other alternative is to use expo's vector Icons. Something like this.
import { Ionicons } from "#expo/vector-icons".
Then render your Icon like this;
<Ionicons
name="ios-exit-outline"
color={colors.danger}
size={28}
style={{ marginRight: -15 }}
/>
Edit this file node_modules\react-native-vector-icons\lib\toolbar-android.js
remove 'import ToolbarAndroid from '#react-native-community/toolbar-android';'
edit return null
for this case you have not toolbar-android in your modules file and as friends saying you can fix it by this command
windows users:
npm install --save #react-native-community/toolbar-android
Mac users:
yarn add #react-native-community/toolbar-android
But IN GENERAL: I wanna tell you an experience for you guys whenever you encounter with this kind of errors that start with "Unable to resolve module" .
if you have a look to the error we have a problem with the module that system is telling us.
if you have not that module . you can install it with the commands
Windows users:
npm install --save THE MODULE(attention: THE MODULE IS THE NAME OF PACKAGES OR MODULES that u need to install)
and Mac users:
yarn add THE MODULE(attention: THE MODULE IS THE NAME OF PACKAGES OR MODULES that u need to install)
for example lets look at this error:
error Unable to resolve module `#react-native-community/slider` from `App.js`: #react-native-community/slider could not be found within the project.
as you can see error is telling us this module could not be found within our project.
so we need install it with this command:
for windows programmers:
npm install --save #react-native-community/slider
and for mac programmers:
yarn add #react-native-community/slider
that's all.
I hope you understand me clearly and do not have problem with unable to resolve module errors and my command be useful for you.
best regards
Mehrad Karampour (MEH)
Related
I'm getting the error:
failed to compile -/src/reportWebVitals.js Module not found: Can't
resolve 'web-vitals'. Since new to react JS, could not find what
happened. Here is the reportWebVitals.JS file. Thanks in advance for
the help. "/src/reportWebVitals.js Module not found: Can't resolve
'web-vitals' in 'E:\ReactResources\RectProjects\test-app\src'"
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}};
export default reportWebVitals;
You need to install web vitals. Open your terminal and run the following command:
npm i web-vitals --save-dev
Also, deleting the whole thing and reinstalling might work, but that's a longer process.
For anyone coming here from starting a brand new app with create-react-app: If you are using npm but run create-react-app without explicitly specifying it, it will use yarn when available.
I was able to bypass this issue by adding the flag --use-npm.
So, for example:
npx create-react-app my-app --use-npm
Source
for me following worked
first do npm uninstall react-scripts
then do npm install react-scripts
Delete all the files & Folders inside test-app folder. Reinstall all the packages now and start npm. It will work.
If you have created your project with create-react-app, all the dependencies should be there when you run npm install.
Make sure you did that by navigating to the root directory and running:
npm install
I closed my terminal and opened again. Works for me!
I recently started having a problem with npm build after upgrading to newer version of react-bootstrap (1.0.0-beta.6).
Creating an optimized production build...
Failed to compile.
Cannot find module: '#restart/context/forwardRef'. Make sure this package is installed.
./node_modules/react-bootstrap/es/ThemeProvider.js
You can install this package by running: yarn add #restart/context/forwardRef.
I tried running the provided yarn command but this is not a valid package name. Does anyone have an idea how to fix this without going back to the old version (which does not support tabs, which is something I am using)?
This is an upstream issue with #restart/context, which just released a version that breaks importing forwardRef like this:
import forwardRef from '#restart/context/forwardRef'
Quick fix is to downgrade to 2.1.2 by running yarn add #restart/context#2.1.2.
Longer term fix is to wait for react-bootstrap to either fix their imports or lock their package.json to this version of #restart/context.
Edit: I added an issue to the react-bootstrap repo to track progress here: https://github.com/react-bootstrap/react-bootstrap/issues/3576
Ecosystem
using npm#6.1.0
using node#v8.11.1
Context
I have a JS project that includes a local dependencie :
package.json :
"dependencies": {
"my_local_module": "file:my_local_module"
},
Then, I published the project as npm private package : so far everything is OK.
Issue
When I try to install my private package, I have this issue :
33 error code ENOLOCAL
34 error Could not install from "node_modules\#my_scope\my_project\my_local_module" as it does not contain a package.json file.
Of course, the package.json file exists. When I try to copy manually the project from gitHub instead of installing it with npm, it works perfectly fine but I really would like to make it works with :
npm install #my_scope\my_project
Is there a specific way to publish packages when they include local dependencies or anything like that ? Thank you for your help.
You can try to delete your package-lock.json file
I had the same problem and error. The package-lock.json was still doing a reference to "file:my_local_module".
I deleted it and re npm installed the module to make it work
I found a report of a similar issue within the npm cli github
https://github.com/npm/cli/issues/1756
It appears this may be an issue with npm v6 (I was using version 6.14.12). Updating npm to v7 seems to have solved this issue for me.
I fetched this kind of error in my react project Can not find module 'react-dev-utils/clearConsole' . React version of my project is 16.2. Actually when I install prop-types with npm then I fetched this error and my project was stopped. I can not run my project again. What is the solution for this?
It looks like you lack some dependencies. In this particular example it is react-dev-utils.
Simple npm install --save-dev react-dev-utils should do.
I'm trying install react-vis-force module but not working properly.
I edited package.json to install 'react-vis-force' vs 0.3.1
But I met error.
Cannot find module './factoryWithTypeCheckers' from node_modules/react-vis-force/dist
How can I fix this?
Based on a solution found in the issues section of another react library, you can resolve this issue by changing the import statement.
import {ForceGraph, ForceGraphNode, ForceGraphLink} from 'react-vis-force/dist/react-vis-force.min.js';
The un-minified version of the code has a missing dependency- the minified version does not. It appears as though npm was using the un-minified version by default.
If you're working with npm try to do it
npm install --save react-vis-force
With --save you save your dependency in package.json
If you have do it before, try npm install for reinstall your dependencies.