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.

App fails to compile with react-native-web

See original GitHub issue

I’m trying to use react-native-paper in conjunction with react-native-web. React-native-web is an npm package which aliases react-native, and allows you to run react-native apps in the browser (ie: no simulator). It renders components as android, and it uses react-native v0.55.

Current behaviour

When I run the app without using react-native-paper, it runs fine. When I use react-native-paper however, I currently get an error message (see below) and the app fails to compile.

Expected behaviour

I expect for the app to run as a react-native-web app, with* react-native-paper* providing components. Below is the error message I receive when I run npm start.

Failed to compile
./node_modules/react-native-paper/src/index.js
SyntaxError: /media/binyamin/Seagate Expansion Drive/Documents/Coding/react-native/my-web-app/node_modules/react-native-paper/src/index.js: Unexpected token (4:12)

  2 | 
  3 | import * as Colors from './styles/colors';
> 4 | import type { Theme as _Theme } from './types';
    |             ^
  5 | 
  6 | export type Theme = _Theme;
  7 | 

Code sample

Github Repo: https://github.com/b3u/my-web-app Just run npm start to reproduce the issue

Screenshots (if applicable)

What have you tried

1. Search Google
2. Search existing issues
3. Create a custom theme
4. Opt out of using icons
5. Downgrade to v2.1.3

Your Environment

software version
ios or android n/a (the web app displays as android)
react-native react-native-web v0.9.8
react-native-paper v2.2.8
node v10.13
npm or yarn npm v6.4.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:45 (18 by maintainers)

github_iconTop GitHub Comments

7reactions
satya164commented, Dec 3, 2018

Also, do you think you can reference this issue on the readme so that others can get helped from it?

We’re planning to publish already transpiled code to NPM so the babel stuff won’t be necessary, but yea, we’ll add a guide to use with react-native-web soon.

5reactions
wendlericaseicommented, Dec 10, 2018

@satya164 Hi!

I got the same error as @b3u, but in my case I used expo to create my base app to use react-native-web.

Is there any specific configuration to webpack from expo?

here is my babel.config.js

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    env: {
      production: {
        plugins: ['react-native-paper/babel'],
      },
    },
  };
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to compile React Native Web - Stack Overflow
In my project - not react-native at all - the same error started popping up yesterday. It seems to be related to babel-loader@8.1.0...
Read more >
Troubleshooting - React Native
These are some common issues you may run into while setting up React Native. ... Execution failed for task ':app:installDebug'.
Read more >
Addressing common errors in React Native - LogRocket Blog
Another error that developers commonly encounter when attempting to run their React Native application is shown below: Unable to load script.
Read more >
react-native-web - npm
"React Native for Web" makes it possible to run React Native components and APIs on the web using React DOM. Documentation. The documentation ......
Read more >
How to Share Code Between React Web and React Native Apps
When you try to import anything outside of src directory, the web app fails to compile. There are multiple ways to fix this...
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