-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot use third-party react native components #222
Comments
Your issue seems a bit vague. It is totally possible (eg: I use https://github.com/oblador/react-native-vector-icons) but it will obviously depends on what the component expect to be available (is there some native code involved? it the code of the module transpiled or not? etc). Hard to say get a precise answer here. You should probably evaluate modules one by one instead of trying to add everything. Also you need to be aware of some differences in some components. |
There are a couple of problems I noticed:
Hope that helps |
@necolas Thanks for the hints. I used |
|
@MoOx Sorry to resurrect this issue - can you please provide some guidance on how to get react-native-vector-icons (and other third party components) working? I keep getting the same "Unexpected token import..." error which is related to react-native components generally not having a compiled source with them. Thanks |
I made a PR on their README. You basically need to transpile the react-native-* modules as they are most of the time published in es6, not transpiled via babel https://github.com/oblador/react-native-vector-icons#web-with-webpack |
What you may miss from this guide is that you need to add "node_modules/react-native-vector-icons" in your babel-loader |
@MoOx thanks for the feed back - I found the info your talking about but including the code below causes an "Uncaught SyntaxError: Unexpected token import" error ;(
{
test: /\.js$/,
exclude: /node_modules/,
include: '/node_modules/react-native-vector-icons',
loader: 'babel-loader',
query: { cacheDirectory: true }
},
|
Just wanted to follow up here for future folks with a few tidbits. The approach is to include the react-native component in your babel compile. In the case of react-native-vector-icons your need to follow @MoOx instructions (which are also listed on the react-native-vector-icons site). One snag I hit was not being able to parse the JSON files so be sure to include the json-loader in your loaders. Example webpack.config.dev.js Also, I used the react-native-web quick start which has the webpack.config.dev.js file in a subfolder, so be sure to make sure you do the correct path etc...
Link to @MoOx directions |
@necolas , how do I make sure that RN packages or module is compiled? Currently, I have mapped metro.config.js file to load the local modules from the node_modules folder. |
See comment above. Metro can't handle that since it's for RN. RNW codebase needs to be compiled with a web bundler, like webpack, rollup, browserify etc |
@MoOx Sorry, If I am missing something from above. I am still facing the Unable to resolve module error, even after the babel loader configuration in webpack.config.js.
I am trying to include react-native-sdk library which is linked from a local directory. I have included the module as in the above webback.config.js -> babelConfiguration file. As I can see there is test: /.js$/ is only for .js file my workspace has the mix of .js and .tsx files is there something specific in my case ? I have created the new issue #1354 with all details of my package and webpack configuration and bable loader configuration. |
npm install --save-dev react-app-rewired Create a
Also create a
Now you can just run |
Hello, I'm using the react native starter kit to setup react native for web projects. My problem is that I can't seem to get third party react native modules to work, even those that doesn't have dependency to the native platform. More details here:
grabcode/react-native-web-starter#12
Environment (include versions)
OS: Ubuntu 16.04
Device: browser
Browser: chrome
React Native for Web (version): ^0.0.44
React (version): 15.3.1
The text was updated successfully, but these errors were encountered: