Cannot read property '_text' of undefined - reactjs

I am just trying to link react-native-fetch-blob library but it is giving error
react-native link react-native-fetch-blob
And error shows
Scanning folders for symlinks in ...\node_modules (48ms)
rnpm-install ERR! ERRPACKAGEJSON No package found. Are you sure this is a React Native project?
Cannot read property '_text' of undefined
I have already installed library using npm install react-native-fetch-blob --save but while linking it is showing error.
Not only for fetch-blob, linking is not working for any of the library.

Ensure you are at the root of the React Native project before running react-native link react-native-fetch-blob.
My guess is that you may currently be within the ios or android folder, so jump back up one directory level.
If you npm installed any packages in your current directory, you will need to remove them, then install them again from the root of the project to ensure they are installed in the right location.

Related

Moved my React Native project folder to a new machine, how do i get it to run?

I recently cloned my React Native project folder from GitHub to my new/unused Mac. I am now in the root directory and when i run "react-native run-ios" to get the project going and load up the phone simulator, i get -bash: react-native: command not found
Do i need to re-install EVERY single dependency in package.json again (because it seems they're all there in my folders)?
Whats's the minimum in need to get my project up and running again and what commands do i use with my current project. I don't want to have to 'react-native init' an entirely new project!
Thanks
If you haven't done any react-native work on the Mac, then yes, you need to install all the dependencies including the react-native cli. You don't have the cli for react-native installed and you are trying to use it. You need to install react-native cli and NPM and make sure all dependencies are there.

What exactly does `pod install` do in react-native's autolinking?

I'm using React Native 0.61, and have been reading about the new auto-linking feature. If you have any insight on ANY of the following questions, I'd appreciate it.
My Questions Are:
1) My understanding of react-native link <module> is that it adds a line for <module> to your Podfile, and then you run pod install. However, for the last year I've been using react-native link and linking manually, and have never run pod install. So am I right that react-native link does more than just add lines to your Podfile?
2) In the past, when react-native link failed to link the module, I manually linked it by dragging the .xcodeproj and .a files into Xcode as described here. Does react-native link (when it works) add the line to your Podfile AND add .xcodeproj and .a files into Xcode for you?
3) Is there anything involved in native modules being linked other than the .xcodeproj and .a files being added to Xcode?
4) What exactly does pod install do? Does it take all the native modules referenced in your Podfile and add .xcodeproj and .a files into Xcode? If so, that would involve two steps: adding the line to your Podfile and then running pod install. Why not just react-native link?
5) My understanding of auto-linking is that it adds lines for all native modules to your Podfile, and then you still have to run pod install. Isn't this just accomplishing the same thing as react-native link?
6) In this guide to auto-linking, it says "Autolinking is a replacement for react-native link. If you have been using React Native before version 0.60, please unlink native dependencies if you have any from a previous install.". Why does it tell you to unlink? If the module is already linked, what will unlinking it and re-linking it do? This implies there's a difference between the way modules are linked with react-native link and via auto-linking. What happens if you auto-link and then pod install, and then try using react-native link, or vice versa?
7) I outlined this in the previous questions, but just to make it concise, what is the difference between auto-linking + pod install and react-native link?
All of your questions are closely intertwined so I'm going to just give you the details that will hopefully clear up things for you.
If React Native version <= 0.59 AND Cocoapods is NOT used in
the project :
react-native link will just add the .xcodeproj file and the .a file to the XCode Project. It will NOT add any lines to the Podfile because in this case, the Podfile doesn't exist.
If React Native version <= 0.59 AND Cocoapods is used in the
project :
react-native link will add the lines to the Podfile and install pods. It will NOT add .xcodeproj or .a file to the XCode Project. This is assuming that the library supports Cocoapods installation. How do you know if the library supports Podfile installation ? They mention it on their Github page/NPM page. Also, such libraries will have a .podspec file as well.
Example : https://github.com/react-native-community/react-native-device-info
See that this library has a .podspec file -> RNDeviceInfo.podspec. So this supports Cocoapods installation.
If the library doesn't support Cocoapods installation, react-native link will just add xcode.proj and .a file to the XCode Project like the above case.
If React Native version >= 0.61 (Cocoapods is default in this case)
react-native link is NOT required anymore.
You just install the library (yarn add or npm install)
And then do pod install.
What happens here is, Cocoapods grabs the library from the node_modules folder, checks if there is a .podspec file and then installs the pods. But it DOESN'T add any lines to the podfile. This is auto-linking that's been introduced in React Native version 0.60.
In case of older libraries that DO NOT have a .podspec file, you need to manually link the library by react-native link.

error while trying to install react-native -floating-action

when I'm trying to install some package
like:
react-native-floating-action
or:
react-native-action-button
I'm running the
npm i react-native-floating-action --save
and when I run react-native link
i get this error:
PS C:\Projects\projectname> react-native link
rnpm-install info Linking assets to ios project
rnpm-install ERR! Something went wrong while linking. Error: Cannot read property 'pbxprojPath' of null
Please file an issue here: https://github.com/facebook/react-native/issues
Cannot read property 'pbxprojPath' of null
TypeError: Cannot read property 'pbxprojPath' of null
at Object.linkAssetsIOS [as copyAssets] (C:\Projects\projectname\node_modules\react-native\local-cli\link\ios\copyAssets.js:24:41)
at C:\Projects\projectname\node_modules\react-native\local-cli\link\link.js:104:12
at Array.forEach (<anonymous>)
at linkAssets (C:\Projects\projectname\node_modules\react-native\local-cli\link\link.js:94:28)
at C:\Projects\projectname\node_modules\react-native\local-cli\link\link.js:171:30
these are my versions:
react-native-cli: 2.0.1
react-native: 0.57.1
npm --version
6.4.1
expo --version
2.6.14
Expo does not support linked binaries. If you require linked binaries, you must first Eject from Expo to ExpoKit or initialize your project using react-native init MyProjName
Reference
If you know that you'll eventually need to include your own native code, Expo is still a good way to get started. In that case you'll just need to "eject" eventually to create your own native builds. If you do eject, the "Building Projects with Native Code" instructions will be required to continue working on your project.
https://facebook.github.io/react-native/docs/getting-started.html
This worked for me:
npm update
react-native link
Eventually, I found the problem,
I needed to run react-native upgrade, and had a different version of react-native in the package.json from the node_modules
writing ^0.57.8 (current react-native version) on the packge.json:
"react-native": "^0.57.8",
running npm install
setting a name for the project in the package.json:
"name":"somename"
and running
react-native upgrade
react-native link
everything was ok
seems to me that it's always a matter of versions with react-native errors

How to fix: Error: ENOENT: no such file or directory 'src/node_modules/native-base/Fonts'

I was following up a tutorial which used expo and needed the fonts for native code, but I'm not using expo thus I don't need those fonts. I removed the code that was using them (nothing that would affect the other parts of the app), and now it gives me this hideous error that it says is located on my source folder "src/navigation/node_modules/native-base/Fonts", the node modules are not even located on the src.
Bear in mind that I'm new to react native, any help would be appreciated.
Terminal output:
bundling failed: Error: ENOENT: no such file or directory, scandir
'/Users/relativity/Documents/ReactNative-Projects/test/src/navigation/node_modules/native-base/Fonts'
Try npm install in your project directory, perhaps you deleted something that wasn't meant to be deleted.
Open terminal and navigate to your project directory and run npm install after it is done run react-native run-android or react-native run-ios
It looks like some default fonts are missing.
npm rebuild native-base is the official solution. Deleting your node_modules and running npm install will also do the trick. If this doesn't work try clearing cache, deleting node_modules and installing packages.

Cannot read property '#global' of undefined - NPM link MUI components

I have created a number of React components which wrap Material-UI components and are packaged as an NPM module.
The module works fine when installed via the remote package: npm install *name-of-package*, or via local install: npm install ../*name-of-package*.
For module development, however, I would like to use npm link so that I can use webpack --watch / webpack-dev-server etc in the module and site directories.
To do so, I am running npm link to create a symlink in the module directory, and then npm link *name-of-package* in the site directory. Webpack starts as expected, however I keep encountering errors in the browser related to MUI's withStyles function:
Uncaught TypeError: Cannot read property '#global' of undefined referring to the var rules = style[propKey]; line of the function handleNestedGlobalContainerRule(rule).
And other such as: The above error occurred in the <WithStyles(Typography)> component
From what I can tell from similar posts this is complaining about the absence of theme object (the site has a MuiThemeProvider with a theme object declared).
Can anyone suggest why this might be working with npm install and not npm link? I cannot seem to figure this one out.
After checking out various commits and reading #AstenMies' reference, I have seemed to have resolved this issue. Or at least I'm no longer able to replicate the problem.
I'm not entirely sure which exact change solved the issue, but I'll list what I did in case someone else finds themselves in this situation:
As #AstenMies' link points to, property in my theme object was undefined (although this on its own didn't solve my issue)
Make sure the React and React-DOM versions of your module and site are the same
Don't mix your yarn add and npm install commmands - mixing package managers can lead to inconsistencies
When in doubt, delete your node_modules folder and install again. Your can also npm cache clean here to avoid any cached nasties

Resources