Closed pgarciacamou closed 7 years ago
Hi @pgarciacamou, thank you for creating this issue. I just released version 1.1.0
which adds support for React Native > 0.40. Could you please try again and let me know if you still encounter this issue? Thank you for you patience.
@frostney excellent timing! I will test right away and let you know.
@frostney
"peerDependencies": {
"react-native": "^0.29.0",
"react-native-windows": "^0.29.0"
}
To reproduce:
I create a library (https://github.com/pgarciacamou/react-native-lib):
mkdir react-native-lib
cd ./react-native-lib
git init && git remote add origin git@github.com:pgarciacamou/react-native-lib.git
react-native-create-library Lib
package.json
-> peer dependencies.git add . && git commit -m "run react-native-create-library" && git push origin master
I created a react-native app (https://github.com/pgarciacamou/LibTest):
react-native init LibTest
cd ./LibTest
git init && git remote add origin git@github.com:pgarciacamou/LibTest.git
npm install react react-native pgarciacamou/react-native-lib#master
git add . && git commit -m "run react-native init" && git push origin master
react-native link
react-native run-ios
I debugged LibTest;
import { NativeModules/*, ... */ } from 'react-native';
import RNLib from 'react-native-lib';
export default class LibTest extends Component {
componentDidMount() {
console.log('RNLib');
console.log(RNLib);
console.log('NativeModules');
console.log(NativeModules);
}
render () { ... }
}
// ...
and this is what I get:
I didn't have time today to test linking manually, I'll try it tomorrow, although TBH this is the minimum viable product and there is no reason why this should not be working.
I'm starting to wonder if it is a bug that was introduced with react-native v0.40
i think it is better to have react-native deps as devDependencies
linking is not working using the master version of this package
@sibelius Thanks for catching this. I'll get right on fixing this.
I figure it out the problem, linking is working fine
I was missing the --save tô add my lib dependency to package.json
@sibelius
i think it is better to have react-native deps as devDependencies
Why?
I was missing the --save tô add my lib dependency to package.json
What? I did this too and it didn't work for me. Are you sure that the NativeModule is not undefined? In my case, I import the npm module just fine, but the NativeModule is undefined so I can't access the methods from Objective-C.
Is there anything else you did different? Could you elaborate a bit more?
@pgarciacamou This is happening to me as well. My obj-c code cannot find React...
#import <React/RCTBridgeModule.h>
not found. Any updates on this?
@ugiacoman what versions of react-native-create-library
, react-native
, react
, react-native-cli
, xcode
do you have?
Also, how are you running the project?
@pgarciacamou
react: 15.4.1 react-native-cli: 2.0.1 react-native: 0.42.3 react-native-create-library: 3.0.2
I don't have react install globally though, do I need to?
I tried opening the xcode project and running, but that didn't work. Also tried opening via react-native run-ios
but couldn't find the header files.
Also for some reason I can't run react-native-create-library -V
@ugiacoman
I'm using
react: 15.4.2 react-native: 0.42.3 react-native-cli: 2.0.1 react-native-create-library: 1.1.0 xcode-select: 2343. node: v6.9.5
I don't have react install globally though, do I need to?
no
I tried opening the xcode project and running, but that didn't work. Also tried opening via react-native run-ios but couldn't find the header files.
Did you try to run the library alone? I believe there is nothing to run, right? react-native-create-library
creates just a library that you can import (I could be wrong tho). Do you mean you created the library and then installed it somewhere else and it errored out?
@ugiacoman when you create the library with react-native-create-library
it creates a README.md file with instructions on how to install/run it, did you follow those?
@ugiacoman let me know if it works for you, I've been meaning to close this issue since this answer I posted in StackOverflow.
@pgarciacamou Ohhh, get it now, it all just came full circle. Thank you so much, it worked!
So the idea is you develop it within another project. Completely makes sense :) Do you think there should be something in the README to clarify the development process?
@ugiacoman
I'm glad it worked! 💪
So the idea is you develop it within another project.
To be honest, I haven't found best practices surrounding this subject (just some ideas here and there), and all the approaches I've found have disadvantages one way or another, so I guess it is up to you.
If you ask me, what I like to do is create a fully working example within the library, which has pros and cons as well 😩... For example, it allows other users to contribute easily (without having to create their own project to test new features or small contributions), but it creates an overhead withing the project (a fully working react-native app, including iOS files, etc...).
Do you think there should be something in the README to clarify the development process?
Not really, IMO that is beyond the functionality of this repo. I think the default README file doesn't include something like that because of the same idea above, the rest should be added by the developer depending on the approach taken to run the library (if any).
As a side note, when I create a working example within the library, I add a relative path to the package.json of the example that points to the parent directory which is the library. E.g:
> some-react-native-lib
- index.js
> example
> some-react-native-project
- package.json
// package.json
// ...
"dependencies": {
"react": "...",
"react-native": "...",
"some-react-native-lib": "../../"
}
// ...
Using:
I did the following:
react-native-create-library Lib
.react-native init RNLibTest
.react-native link
) and manual way: both following the scaffolded instructions of this repo AND following the linking section of react-native docs.The result is just saying that the library is
undefined
as if react-native didn't find it inNativeModules
.Anyone else is encountering this issue? I created a stackoverflow question to keep this issue clean: http://stackoverflow.com/questions/42281942/library-not-linking-with-newer-versions-of-react-native
ping: @frostney