question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Button compile failure on Web with react-native-web

See original GitHub issue

Explain what you did While following https://react-native-training.github.io/react-native-elements/blog/2018/12/13/react-native-web.html, `import { Button } from ‘react-native-elements’ triggers screenshot below.

Native (Android) would render Button fine.

Expected behaviour Button renders on Web, as it does on native platforms.

Describe the bug image

To Reproduce Follow https://react-native-training.github.io/react-native-elements/blog/2018/12/13/react-native-web.html

In src/App.js:

import { Button } from 'react-native-elements

Run yarn web

Your Environment (please complete the following information):

software version
react-native-elements 1.1.0
react-native 0.55.4
npm or yarn yarn: 1.13.0

Related: #882

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:36 (17 by maintainers)

github_iconTop GitHub Comments

13reactions
oxyiicommented, Mar 2, 2019

@fungilation Metro react-native bundler compile modules in node_modules. And most libraries for react-native are published without compilation. But RNWeb applications compile with react-scripts like standard React application. So you must eject your application for including node_modules libraries into babel. See this discussion about babel config without ejecting.

If you don’t want to eject you can replace react-scripts with react-app-rewired and change babel config using customize-cra. Ok, step-by-step:

  1. npm install --save-dev react-app-rewired customize-cra @babel/plugin-proposal-class-properties

  2. Change scripts in your package.json:

...
"scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
}
...
  1. Create config-overrides.js in your project root
const path = require("path");
const {override, addBabelPlugins, babelInclude} = require("customize-cra");

module.exports = override(
    babelInclude([
        path.resolve("src"), // your src folder can be another
        path.resolve("node_modules/react-native-elements"),
        path.resolve("node_modules/react-native-ratings"),
        path.resolve("node_modules/react-native-status-bar-height"), // <- I'm not sure that this is necessary
        path.resolve("node_modules/react-native-vector-icons"),
    ]),
    addBabelPlugins(
        "@babel/plugin-proposal-class-properties",
    ),
);

And woo a la - react-native-elements buttons works fine without ejecting!

P.S. @babel/plugin-proposal-class-properties plugin resolve static class properties like propTypes or defaultProps.

P.P.S. Sorry for my english )))

9reactions
oxyiicommented, Mar 5, 2019

@fungilation I’m going out this issue. I recommend you to read about webpack and babel.

From your repo, after install deps and @babel/plugin-proposal-class-properties

config

result

Read more comments on GitHub >

github_iconTop Results From Across the Web

compiler errors - React-Native-Web configuration issue
When I launch it in the browser after Expo start (Using this command - EXPO_WEB_DEBUG=true expo build:web ) it gives me an error...
Read more >
The complete guide to React Native for Web - LogRocket Blog
Explore the massive potential and the current drawbacks of React Native for Web and explain how to set up a demo project.
Read more >
How to add React Native Web to an existing ... - Aryan Goharzad
React Native for Web allows you to make your React Native application ... The first step is compiling any native library to the...
Read more >
Introduction to React Native for Web
React Native for Web uses React DOM to accurately render React Native compatible JavaScript code in a web browser.
Read more >
Testing - React Native
This guide introduces React Native developers to the key concepts ... to fix a bug in your code is to write a failing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found