Git Product home page Git Product logo

gatsby-plugin-react-native-web's Introduction

Gatsby plugin for React-Native-Web / Expo

NPM Build Status

Adds React-Native-Web and Expo support to a Gatsby site.

Example "production" usage on my blog: sebastienlorber.com/using-expo-in-gatsby


Sponsor

ThisWeekInReact.com: the best newsletter to stay up-to-date with the React ecosystem:

ThisWeekInReact.com banner


Why

Main reasons:

  • sharing components between your mobile app and your static website.
  • using atomic CSS-in-JS with React-Native-Web

Cross-platform code is finally taking off, and it's time to share more code between web and mobile. There's already Expo web, but it is not suited for a marketing website that needs JAMStack / SEO / CMS integration / Performance / Gatsby-image ... This project aims to "merge" Expo for web with Gatsby, so that you can build useful things like:

  • Share a universal cross-platform design system between your mobile app and your marketing website
  • Blog about ReactNative, and include runnable RN demos directly in your MDX
  • Document your ReactNative components with Docz
  • Use ReactNativeWeb as a performant CSS-in-JS lib, like Twitter does (see atomic CSS-in-JS).

Supported features

This plugin uses the same setup as Expo for web, thanks to @expo/webpack-config

Support includes:

  • Primitive components from ReactNative (check RNW support)
  • Expo unimodules with web support like expo-camera (check Expo doc for support)
  • .web.js extension handling
  • Universal ReactNative design system libraries, like react-native-paper, react-native-ui-kitten...
  • Universal gesture systems with Animated, react-native-gesture-handler or Reanimated.
  • Universal SVG components using react-native-svg
  • Automatic transpilation of third party react-native libs
  • Works in MDX
  • Works in Docz (Gatsby-based)

Recipe

Use the new Gatsby Recipe feature to get started fast:

gatsby recipes https://raw.githubusercontent.com/slorber/gatsby-plugin-react-native-web/master/recipe.mdx

Manual setup

1. Install required dependencies

yarn add react-native react-native-web@~0.11.7 gatsby-plugin-react-native-web expo

2. Create a gatsby-config.js and use the plugin:

   module.exports = {
     plugins: [
       `gatsby-plugin-react-native-web`,
     ],
   }

3. Install additional cross-platform libraries / unimodules (optional)

Add expo audio/video components:

yarn add expo-av

4. Create a test pages

Create an example page like this one in your ./pages folder, or try importing React-Native / Expo components into an existing one.


Demo

The examples folder have runnable Gatsby site demos. They are also hosted:

Example usage

Very basic example:

import React from 'react'
import Link from 'gatsby-link'
import { StyleSheet, TouchableOpacity, Text, View } from 'react-native'

const styles = StyleSheet.create({
  box: { padding: 10, margin: 10, borderWidth: 1, borderColor: 'black' },
  text: { fontWeight: 'bold', color: 'red' },
  button: {
    marginVertical: 40,
    paddingVertical: 20,
    paddingHorizontal: 10,
    borderWidth: 1,
    borderColor: 'black',
    backgroundColor: 'lightgrey',
    alignItems: 'center',
  },
  buttonText: { fontWeight: 'bold', color: 'black' },
})

const IndexPage = () => (
  <View style={styles.box}>
    <Text style={styles.text}>
      Hi this is React-Native-Web rendered by Gatsby
    </Text>
    <TouchableOpacity style={styles.button} onPress={() => alert('it works')}>
      <Text style={styles.buttonText}>Button</Text>
    </TouchableOpacity>
    <Link to="/page-2/">Go to page 2</Link>
  </View>
)

export default IndexPage

image

How does it work

  • Adds babel-preset-expo which manages tree-shaking of react-native-web packages.
  • Implements module resolution for files with platform extensions like .web.js, .web.tsx...
  • Uses @expo/webpack-config which creates aliases for various React Native asset features and ensures that all React Native packages, and Unimodules are loaded with Babel.
  • Creates support for Gatsby SSR with react-native-web
  • Extracts critical CSS with the StyleSheet api of react-native-web and adds it to the static page.

FAQ

Expo already has web support, why do I need this?

Expo web support is more like Create-React-App, it only outputs a single html file and does client side routing. It works fine for apps, but miss the various benefits of Gatsby, including performance, SEO, CMS integration, Gatsby-image...

Actually, this plugin uses the same webpack config as Expo web support, and Expo (Evan Bacon) contributed to this project. You'll also find support for Next if you need a static/SSR hybrid.

How to share code for navigation/routing?

This is not easy, because navigation patterns are different between web and mobile.

ReactNavigation may have web support, but Gatsby can't use ReactNavigation config easily to construct static pages.

You'd rather keep using platform-specific navigation trees (pages for Gatsby, and stacks/tabs for ReactNavigation).

Eventually you could build your own cross-platform navigate() function, and your own cross-platform Link component (take a look at expo-gatsby-navigation).

Can I share the same repo to build a mobile app and a Gatsby site with shared components?

The most simple way to share code between an Expo app and a Gatsby site is currently to use a single folder for both the Expo app and the Gatsby app.

Otherwise you can try to setup a monorepo, but keep in mind this requires more complex configuration, and Metro does not follow symlinks.

You can also read the Expo doc about adding Gatsby support to an existing app.

How can I publish an universal cross-platform component that works on web and mobile?

You can take a loot at this example: expo-dark-mode-switch. It uses expo-module-scripts.

You can also check react-native-community/bob

Hire a freelance expert

Looking for a React/ReactNative freelance expert with more than 5 years production experience? Contact me from my website or with Twitter.

gatsby-plugin-react-native-web's People

Contributors

evanbacon avatar jasonleonhard avatar minheq avatar mottox2 avatar oieduardorabelo avatar slorber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gatsby-plugin-react-native-web's Issues

Let .gatsby.js extension override .web.js ?

@nandorojo has 2 cool projects for cross-platform navigation, yet using platform native navigation solution (ie, not necessarily using react-navigation on web, but instead next or gatsby).

Raw idea here, but wondering if it wouldn't be useful to have .next.js and .gatsby.js extension override .web.js, in the same way .ios.js and .android.js can override .native.js

@EvanBacon have you thought about this?

v3 static query problems

v3 does not support useStaticQuery

image

@sidharthachatterjee maybe you could give some insights here?

@EvanBacon brought Expo SDK support to this plugin in v3. Basically, Expo apis (usually for RN) now offer a binding for web, so they can also work in Gatsby too.

The thing is:

  • Gatsby has a complex webpack config / babel loader
  • Expo web has a complex webpack config / babel loader
  • Somehow we need to make the 2 play well together, or merge them

The webpack config of gatsby is "modified" by this method:
https://github.com/expo/expo-cli/blob/master/packages/webpack-config/src/addons/withUnimodules.ts#L22

It adds the expo babel loader (which is able to transpile RN modules) at the end of the webpack rules (so afaik it takes priority over the gatsby one).

So we have gatsbyLoader(expoLoader(jsCode)) somehow (at least for code in /src)

So, when gatsby loader (which has the static queries setup) do his work, the static queries may already have been "processed" (not sure how babel works), and now the gatsby loader do not recognize them anymore (???not sure about that???).

@sidharthachatterjee by chance do you know if it's possible to make static queries work with this gatsbyLoader(expoLoader(jsCode)) setup?

The problems I see:

  • It might be complex to merge expo loader into gatsby loader.
  • the Expo Webpack config should also be easy to apply to other frameworks as well (NextJS, CRA, Electron...)

error _utils.getModuleFileExtensions is not a function

got an error when running yarn gatsby develop, error output says

"gatsby-plugin-react-native-web" threw an error while running the resolvableExtensions lifecycle:
(0 , _utils.getModuleFileExtensions) is not a function
  TypeError: (0 , _utils.getModuleFileExtensions) is not a function
  - gatsby-node.js:9 Object.resolvableExtensions
    [HaloService]/[gatsby-plugin-react-native-web]/gatsby-node.js:9:71

  - api-runner-node.js:235 runAPI
    [HaloService]/[gatsby]/dist/utils/api-runner-node.js:235:41

  - api-runner-node.js:375 Promise.catch.pluginName
    [HaloService]/[gatsby]/dist/utils/api-runner-node.js:375:13

  - new Promise

  - api-runner-node.js:374 runPlugin
    [HaloService]/[gatsby]/dist/utils/api-runner-node.js:374:10

  - api-runner-node.js:328 module.exports
    [HaloService]/[gatsby]/dist/utils/api-runner-node.js:328:24

  - index.js:420 module.exports
    [HaloService]/[gatsby]/dist/bootstrap/index.js:420:28

  - develop.js:419 async module.exports
    [HaloService]/[gatsby]/dist/commands/develop.js:419:7

im using "gatsby-plugin-react-native-web": "^3.0.0-beta.2"

How can I build my Android project or run my site in an Android emulator?

I now have a Gatsby site that's using this gatsby-plugin-react-native-web. I can output React Native components on my site but I couldn't find any Android project in my Gatsby project folder.

How can I build my Android project or run my site in an Android emulator?
Is there any documentation or guides for it?

I keep seeing this upon running react-native run-android:

Android project not found. Maybe run react-native android first?

Missing external configuration for type:commonjs2

Steps to reproduce:

  1. Create new starter site

Instructions taken from here: https://github.com/slorber/gatsby-plugin-react-native-web#manual-setup

gatsby new [project-name]
cd [project-name]
yarn add react-native react-native-web@~0.11.7 gatsby-plugin-react-native-web expo
  1. Update gatsby config:
module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    `gatsby-plugin-react-native-web`,
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}
  1. Launch the site
yarn develop

This also fails with the same error message if using the recipe method in the README:

gatsby new [project-name]
cd [project-name]
gatsby recipes https://raw.githubusercontent.com/slorber/gatsby-plugin-react-native-web/master/recipe.mdx
yarn develop

v3 static query problems still...

I looked through #23 and did not see a clear solouton to my problem.

NOTE: My static query works fine when running gatsby develop and my components build successfully.

Basically as soon as I add this plugin, my static query breaks when running gatsby build:

❯ gatsby build                                                                                                                                                                                                                                                                               [30/33455]
success open and validate gatsby-configs - 0.221s                                                                                                                                                                                                                                                      
success load plugins - 1.119s                                                                                                                                                                                                                                                                          
success onPreInit - 0.039s                                                                                                                                                                                                                                                                             
success delete html and css files from previous builds - 0.004s                                                                                                                                                                                                                                        
success initialize cache - 0.007s                                                                                                                                                                                                                                                                      
success copy gatsby files - 0.033s                                                                                                                                                                                                                                                                     
success onPreBootstrap - 0.018s                                                                                                                                                                                                                                                                        
success createSchemaCustomization - 0.041s                                                                                                                                                                                                                                                             
success Checking for changed pages - 0.001s                                                                                                                                                                                                                                                            
success source and transform nodes - 0.953s                                                                                                                                                                                                                                                            
success building schema - 0.413s                                                                                                                                                                                                                                                                       
info Total nodes: 96, SitePage nodes: 2 (use --verbose for breakdown)                                                                                                                                                                                                                                  
success createPages - 0.021s                                                                                                                                                                                                                                                                           
success Checking for changed pages - 0.001s                                                                                                                                                                                                                                                            
success createPagesStatefully - 0.072s                                                                                                                                                                                                                                                                 
success update schema - 0.023s                                                                                                                                                                                                                                                                         
success onPreExtractQueries - 0.001s                                                                                                                                                                                                                                                                   
success extract queries from components - 0.451s                                                                                                                                                                                                                                                       
success write out redirect data - 0.002s                                                                                                                                                                                                                                                               
success onPostBootstrap - 0.002s                                                                                                                                                                                                                                                                       
info bootstrap finished - 6.045s                                                                                                                                                                                                                                                                       
success run static queries - 0.014s - 1/1 70.19/s                                                                                                                                                                                                                                                      
success run page queries - 0.515s - 3/3 5.83/s                                                                                                                                                                                                                                                         
success write out requires - 0.019s                                                                                                                                                                                                                                                                    
success Building production JavaScript and CSS bundles - 21.871s                                                                                                                                                                                                                                       
success Rewriting compilation hashes - 0.004s                                                                                                                                                                                                                                                          
success Building HTML renderer - 25.199s                                                                                                                                                                                                                                                               
[============================]   47.812 s 58/58 100% Generating image thumbnails                                                                                                                                                                                                                       
[                            ]   0.000 s 0/3 0% Building static HTML for pages                                                                                                                                                                                                                         

failed Building static HTML for pages - 0.187s

 ERROR #95313 

Building static HTML failed for path "/"

See our docs page for more info on this error: https://gatsby.dev/debug-html


   5 | import { JsonLd } from './jsonLd';
   6 | 
>  7 | function SEO({ description, lang, meta, keywords, title }) {
     |                                                            ^
   8 |     const { site } = useStaticQuery(graphql`
   9 |         query DefaultSEOQuery {
  10 |             site {


  WebpackError: The result of this StaticQuery could not be fetched.
   
  - seo.js:7 
    src/components/seo.js:7:60
   
  - gatsby-ssr.js:27 
    node_modules/gatsby-plugin-react-native-web/gatsby-ssr.js:27:46
   
  - arrayLikeToArray.js:8 
    node_modules/@babel/runtime/helpers/arrayLikeToArray.js:8:1
   

not finished Generating image thumbnails - 48.030s

I tried adding a babel.config.js as described in #23 but that did not help, I also made sure I had the latest version of this plugin installed:

dist-tags:
latest: 3.1.0  
published 9 months ago by slorber <[email protected]>

When I remove the plugin from my gatsby-config.js gatsby build works fine again.

Any advice on how to debug and/or fix this would be greatly appreciated!

add more config options

Having more plugin config options would be helpful.

Some RNW compatible libs seems to require additional setup to work properly.

For example react-native-paper https://callstack.github.io/react-native-paper/using-on-the-web.html

This plugin should allow to easily use such a lib and offer more config options to support the required setup of such libs. Eventually we could add a preset system or something to make config more easy?

Error when running `gatsby build` in Yarn workspace

Current Behavior

When running gatsby build in a monorepo using Yarn workspaces, the build fails with the following output:

success open and validate gatsby-configs - 0.033s
success load plugins - 2.122s
success onPreInit - 0.029s
success delete html and css files from previous builds - 0.006s
success initialize cache - 0.013s
success copy gatsby files - 0.044s
success onPreBootstrap - 0.020s
success createSchemaCustomization - 0.006s
success Checking for changed pages - 0.002s
success source and transform nodes - 0.058s
success building schema - 0.241s
info Total nodes: 36, SitePage nodes: 1 (use --verbose for breakdown)
success createPages - 0.002s
success Checking for changed pages - 0.001s
success createPagesStatefully - 0.049s
success Cleaning up stale page-data - 0.002s
success update schema - 0.018s
success onPreExtractQueries - 0.001s
success extract queries from components - 0.359s
success write out redirect data - 0.006s
success Build manifest and related icons - 0.066s
success onPostBootstrap - 0.070s
info bootstrap finished - 7.888s
success run static queries - 0.017s - 1/1 60.20/s
success run page queries - 0.011s - 4/4 354.30/s
success write out requires - 0.005s

 ERROR

TypeError: Cannot read property 'plugins' of undefined
    at customizeExpoJsLoader (/Users/tlmader/dev/indienav/node_modules/gatsby-plugin-react-native-web/gatsby-node.js:37:71)
    at Object.onCreateWebpackConfig (/Users/tlmader/dev/indienav/node_modules/gatsby-plugin-react-native-web/gatsby-node.js:69:14)
    at runAPI (/Users/tlmader/dev/indienav/node_modules/gatsby/src/utils/api-runner-node.js:460:22)
    at resolve (/Users/tlmader/dev/indienav/node_modules/gatsby/src/utils/api-runner-node.js:589:17)
    at Promise._execute (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/promise.js:103:10)
    at Promise.mapSeries.plugin (/Users/tlmader/dev/indienav/node_modules/gatsby/src/utils/api-runner-node.js:588:14)
    at tryCatcher (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/reduce.js:166:18)
    at Object.gotAccum (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/reduce.js:155:25)
    at Object.tryCatcher (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/tlmader/dev/indienav/node_modules/bluebird/js/release/promise.js:729:18)

not finished Building production JavaScript and CSS bundles - 0.227s

Expected Behavior

gatsby-build should successfully build the application in a Yarn workspace.

Workaround

As a workaround, I hosted gatsby-plugin-react-native-web and its dependencies to the child package.json:

  "workspaces": {
    "nohoist": [
      "react-native",
      "react-native-web",
      "gatsby-plugin-react-native-web",
      "expo"
    ]
  }

However, this causes numerous errors resolving react-native-web in other dependencies installed in the root node_modules, for example:

Can't resolve 'react-native-web/dist/exports/TouchableWithoutFeedback' in '/Users/tlmader/Dev/indienav/node_modules/react-native-elements/src/avatar'

If you're trying to use a package make sure that 'react-native-web/dist/exports/TouchableWithoutFeedback' is installed. If you're trying to use a local file make sure that the path is correct.
error undefined failed

I added react-native-web to the root package.json to prevent these errors.

Web package.json

"dependencies": {
    "@stripe/react-stripe-js": "^1.1.2",
    "@stripe/stripe-js": "^1.11.0",
    "expo": "^39.0.3",
    "gatsby": "^2.25.3",
    "gatsby-image": "^2.4.21",
    "gatsby-plugin-create-client-paths": "^2.3.13",
    "gatsby-plugin-manifest": "^2.5.2",
    "gatsby-plugin-offline": "^3.3.2",
    "gatsby-plugin-react-helmet": "^3.3.14",
    "gatsby-plugin-react-native-web": "^3.1.0",
    "gatsby-plugin-sharp": "^2.7.1",
    "gatsby-plugin-typescript": "^2.5.0",
    "gatsby-source-filesystem": "^2.4.1",
    "gatsby-source-graphql": "^2.7.7",
    "gatsby-transformer-sharp": "^2.5.21",
    "isomorphic-fetch": "^2.2.1",
    "modal-react-native-web": "^0.2.0",
    "react-helmet": "^5.2.1",
    "react-native": "0.63.3",
    "react-native-dropdownalert": "^4.3.0",
    "react-native-gesture-handler": "https://github.com/software-mansion/react-native-gesture-handler.git#95bfb4df7ce9b1e222d50ead99eee7e27cd79043",
    "react-native-masked-text": "^1.13.0",
    "react-native-smooth-pincode-input": "^1.0.9",
    "react-native-web": "~0.11.7",
    "ts-loader": "^6.2.2"
  },
  "devDependencies": {
    "@pmmmwh/react-refresh-webpack-plugin": "^0.2.0",
    "@types/reach__router": "^1.3.6",
    "@types/react-helmet": "^5.0.15",
    "@types/react-stripe-elements": "^6.0.4"
  },
  "workspaces": {
    "nohoist": [
      "react-native",
      "react-native-web",
      "gatsby-plugin-react-native-web",
      "expo"
    ]
  }

Root package.json

  "dependencies": {
    "@apollo/client": "^3.2.5",
    "@indienav/common": "^1.0.0",
    "aws-amplify": "^3.3.11",
    "aws-appsync-auth-link": "^3.0.2",
    "aws-appsync-subscription-link": "^3.0.3",
    "graphql": "^15.4.0",
    "lodash": "^4.17.20",
    "moment": "^2.22.2",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "0.63.3",
    "react-native-elements": "^3.0.0-alpha.1",
    "react-native-vector-icons": "^7.1.0",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "^1.19.2",
    "@graphql-codegen/introspection": "^1.18.0",
    "@graphql-codegen/typescript": "^1.17.11",
    "@graphql-codegen/typescript-document-nodes": "^1.17.8",
    "@graphql-codegen/typescript-graphql-files-modules": "^1.18.0",
    "@graphql-codegen/typescript-operations": "^1.17.10",
    "@graphql-codegen/typescript-react-apollo": "^2.1.1",
    "@semantic-release/git": "^7.0.16",
    "@types/jest": "^25.1.4",
    "@types/lodash": "^4.14.165",
    "@types/react": "~16.9.35",
    "@types/react-native": "^0.63.37",
    "husky": "^4.2.3",
    "jest": "^25.1.0",
    "lerna": "^3.20.2",
    "lint-staged": "^10.0.7",
    "patch-package": "^6.2.2",
    "postinstall-postinstall": "^2.1.0",
    "prettier": "^2.0.2",
    "query-string": "^6.13.7",
    "semantic-release": "^17.2.3",
    "ts-jest": "^25.2.1",
    "typescript": "^3.8.3"
  },
  "workspaces": [
    "packages/*"
  ]

Environment Info

  System:
    OS: macOS 10.15.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 608.54 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.21.0 - ~/.nvm/versions/node/v10.21.0/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v10.21.0/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v10.21.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.0 - /Users/tlmader/.rvm/gems/ruby-2.6.3/bin/pod
    Gradle: 6.1.1 - /usr/local/bin/gradle
    Homebrew: 2.5.6 - /usr/local/bin/brew
    pip2: 19.2.3 - /usr/local/bin/pip2
    pip3: 20.2.3 - /usr/local/bin/pip3
    RubyGems: 3.0.6 - /Users/tlmader/.rvm/rubies/ruby-2.6.3/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.25.0 - /usr/local/bin/git
    Clang: 1200.0.32.27 - /usr/bin/clang
  Servers:
    Apache: 2.4.41 - /usr/sbin/apachectl
  SDKs:
    iOS SDK:
      Platforms: iOS 14.2, DriverKit 20.0, macOS 11.0, tvOS 14.2, watchOS 7.1
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Nano: 2.0.6 - /usr/bin/nano
    VSCode: 1.51.1 - /usr/local/bin/code
    Vim: 8.1 - /usr/bin/vim
    Xcode: 12.2/12B45b - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Java: 12.0.2 - /usr/bin/javac
    Perl: 5.18.4 - /usr/bin/perl
    PHP: 7.3.11 - /usr/bin/php
    Python: 2.7.16 - /usr/bin/python
    Python3: 3.8.6 - /usr/local/bin/python3
    Ruby: 2.6.3 - /Users/tlmader/.rvm/rubies/ruby-2.6.3/bin/ruby
  Databases:
    SQLite: 3.28.0 - /Users/tlmader/Library/Android/sdk/platform-tools/sqlite3
  Browsers:
    Chrome: 87.0.4280.88
    Safari: 14.0
  Monorepos:
    Yarn Workspaces: 1.22.4

Do we need expo to use this lib?

Uses @expo/webpack-config which creates aliases for various React Native asset features and ensures that all React Native packages, and Unimodules are loaded with Babel

I don't get what the dependency on @expo/webpack-config implies.
Can you clarify please?
Can we use this lib when we are not using expo ? (other than @expo/webpack-config)

Build failing in monorepo

I'm getting this error. I've tried various stuffs but can't fix. I have a monorepo using workspaces and the react-native side is working well. I've setup wml and all. But gatsby is not working.

ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Can't resolve '@pmmmwh/react-refresh-webpack-plugin/src/overlay' in '*******/web/.cache'

File: .cache/error-overlay-handler.js


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (14:12)

File: node_modules/@myapp/common/dist/App.js:14:12

Also the second error is really weird, it points to this

const App = () => {
    return (<>
           ~~~^~~~~
      <StatusBar barStyle="dark-content"/>

Cannot read property 'map' of undefined in production

I installed the packages in the README and added gatsby-plugin-react-native-web to gatsbyjs-config. Everything works fine in development, but building the site and serving it in production causes the error below:

Codinhood | Codinhood 2020-05-12 07-11-24

"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-native": "^0.62.2",
"react-native-web": "^0.11.7",
"expo": "^37.0.10",
"gatsby": "^2.18.12",
"gatsby-plugin-react-native-web": "^3.1.0",

If I remove the plugin from the config then the issue goes away. I've used V2.0.0 on other Gatsbyjs sites, like https://material-bread.org, without running into this issue. Any ideas what might be wrong?

Plugin breaks when using UI Kitten v5

Switching to use the new version of UI Kittens v5 breaks the ability to run Gatsby. New package is "@ui-kitten/components"

This can be reproduced by changing the package and the corresponding imports in the example provided. The only clue is an error message about an unexpected token, but no other information.

Who is using this?

Hi,

I'd like to know who is currently using this plugin to build real things? Particularly the newest releases.

As I'm not currently using my own plugin, I don't know exactly if the newest releases work fine so any feedback is welcome :)

styles that depend dimension/layout APIs

I have styles that depend upon the dimension/layout API. In my gatsby-ssr/onRenderBody, I have been calling Dimensions.set (as per necolas/react-native-web#1225) with mobile dimensions, taking a 'mobile-first' approach to styling/rendering. In addition, my components are wrapped in a dimensions aware context/consumer. The issue is that the mobile styles are cached when accessed on desktop. I tried to remedy this by calling Dimensions._update from gatsby-browser/onInitialClientRender, but this did not trigger style re-calculation.

So the question, what is the best approach to set initial dimensions for ssr rendering?

Breaks with Gatsby v4

  TypeError: getResolve is not a function
  
  - webpack.config.js:767 
    [skyhitz]/[gatsby]/src/utils/webpack.config.js:767:26
  
  - withUnimodules.ts:203 
    [skyhitz]/[@expo]/webpack-config/src/addons/withUnimodules.ts:203:52
  
  - ExternalModuleFactoryPlugin.js:21 
    [skyhitz]/[webpack]/lib/ExternalModuleFactoryPlugin.js:21:21
  
  - util:124 deprecated
    node:internal/util:124:12
  
  - ExternalModuleFactoryPlugin.js:169 handleExternals
    [skyhitz]/[webpack]/lib/ExternalModuleFactoryPlugin.js:169:8
  
  - ExternalModuleFactoryPlugin.js:147 next
    [skyhitz]/[webpack]/lib/ExternalModuleFactoryPlugin.js:147:9
  
  - ExternalModuleFactoryPlugin.js:152 handleExternals
    [skyhitz]/[webpack]/lib/ExternalModuleFactoryPlugin.js:152:7
  
  - ExternalModuleFactoryPlugin.js:249 
    [skyhitz]/[webpack]/lib/ExternalModuleFactoryPlugin.js:249:5
  
  
  - NormalModuleFactory.js:796 
    [skyhitz]/[webpack]/lib/NormalModuleFactory.js:796:25
  
  
  - NormalModuleFactory.js:768 NormalModuleFactory.create
    [skyhitz]/[webpack]/lib/NormalModuleFactory.js:768:28
  
  - Compilation.js:1973 Compilation._factorizeModule
    [skyhitz]/[webpack]/lib/Compilation.js:1973:11
  
  - AsyncQueue.js:303 
    [skyhitz]/[webpack]/lib/util/AsyncQueue.js:303:10
  
  
  - AsyncQueue.js:293 AsyncQueue._startProcessing
    [skyhitz]/[webpack]/lib/util/AsyncQueue.js:293:26

    ```

react-native-reanimated

Is this plugin compatible with react-native-reanimated? I don't know what's happening under the hoods, but declaring a simple new Animated.Value(0) throw a lot of errors:

Browser

./node_modules/react-native-reanimated/src/core/AnimatedBezier.js 129:8
Module parse failed: Unexpected token (129:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| export default class AnimatedBezier extends AnimatedNode {
>   _value;
|   _bezier;

Terminal

 ~/Pr/gatsby-site  master !4 ?2  gatsby develop                ✔  16:50:14
❯ gatsby develop
success open and validate gatsby-configs - 0.071s
success load plugins - 0.741s
success onPreInit - 0.003s
success initialize cache - 0.012s
success copy gatsby files - 0.261s
success onPreBootstrap - 0.016s
success createSchemaCustomization - 0.004s
success source and transform nodes - 0.088s
warn Plugin `gatsby-source-filesystem` tried to define the GraphQL type `File`,
success building schema - 0.357s
success createPages - 0.005s
success createPagesStatefully - 0.107s
success onPreExtractQueries - 0.003s
success update schema - 0.036s
success extract queries from components - 0.274s
success write out requires - 0.040s
success write out redirect data - 0.003s
success Build manifest and related icons - 0.133s
success onPostBootstrap - 0.194s
⠀
info bootstrap finished - 6.622 s
⠀
success run queries - 0.045s - 14/14 309.76/s

 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (129:8)

File: node_modules/react-native-reanimated/src/core/AnimatedBezier.js:129:8


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (12:10)

File: node_modules/react-native-reanimated/src/animations/TimingAnimation.js:12:10


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (13:11)

File: node_modules/react-native-reanimated/src/core/AnimatedCall.js:13:11


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (27:40)

File: node_modules/react-native-reanimated/src/createAnimatedComponent.js:27:40


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (36:6)

File: node_modules/react-native-reanimated/src/Transitioning.js:36:6


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (5:7)

File: node_modules/react-native-reanimated/src/core/AnimatedAlways.js:5:7


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (60:8)

File: node_modules/react-native-reanimated/src/core/AnimatedOperator.js:60:8


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (6:12)

File: node_modules/react-native-reanimated/src/core/AnimatedClockTest.js:6:12


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (6:12)

File: node_modules/react-native-reanimated/src/core/AnimatedCond.js:6:12


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (6:12)

File: node_modules/react-native-reanimated/src/core/AnimatedStartClock.js:6:12


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (6:12)

File: node_modules/react-native-reanimated/src/core/AnimatedStopClock.js:6:12


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (6:16)

File: node_modules/react-native-reanimated/src/core/AnimatedClock.js:6:16


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (6:21)

File: node_modules/react-native-reanimated/src/core/AnimatedCode.js:6:21


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (6:8)

File: node_modules/react-native-reanimated/src/core/AnimatedBlock.js:6:8


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (7:10)

File: node_modules/react-native-reanimated/src/core/AnimatedDebug.js:7:10


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (7:7)

File: node_modules/react-native-reanimated/src/core/AnimatedFunction.js:7:7


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (86:15)

File: node_modules/react-native-reanimated/src/core/AnimatedNode.js:86:15


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (8:7)

File: node_modules/react-native-reanimated/src/core/AnimatedSet.js:8:7


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Unexpected token (98:13)

File: node_modules/react-native-reanimated/src/core/AnimatedEvent.js:98:13

failed Building development bundle - 4.594s

@EvanBacon I saw that you've got reanimated web examples running, is there anything we must do before make it works?

I can take a look on it with some initial help.

PS: using 2.0.0-beta.0version

Thanks guys!

Error when running `yarn develop`

TypeError: Cannot read property 'plugins' of undefined
    at customizeExpoJsLoader (./node_modules/gatsby-plugin-react-native-web/gatsby-node.js:37:71)

"gatsby-plugin-react-native-web": "^3.1.0",

Generating development SSR bundle failed

I followed the Expo guide in the documentation. Click here.
I've already checked just running a pure Gatsby project and there is no problem.

I use a M1 MacBook Pro.

While trying to run gatsby develop for the first time in the project it shows this in the VScode terminal:

warn Plugin gatsby-plugin-react-native-web is not compatible with your gatsby version 3.2.1 - It requires gatsby@^2.0.0
warn Plugin gatsby-plugin-react-native-web is not compatible with your gatsby version 3.2.1 - It requires gatsby@^2.0.0
success load plugins - 0.614s
success onPreInit - 0.010s
success initialize cache - 0.009s
success copy gatsby files - 0.042s
success onPreBootstrap - 0.009s
success createSchemaCustomization - 0.001s
success Checking for changed pages - 0.001s
success source and transform nodes - 0.024s
success building schema - 0.105s
info Total nodes: 20, SitePage nodes: 1 (use --verbose for breakdown)
success createPages - 0.002s
success Checking for changed pages - 0.000s
success createPagesStatefully - 0.016s
success update schema - 0.021s
success write out redirect data - 0.001s
success onPostBootstrap - 0.001s
info bootstrap finished - 2.203s
success onPreExtractQueries - 0.001s
success extract queries from components - 0.056s
success write out requires - 0.003s
success run page queries - 0.013s - 1/1 78.76/s

 ERROR 

(node:10467) [DEP_WEBPACK_EXTERNALS_FUNCTION_PARAMETERS] DeprecationWarning: The externals-function should be defined like ({context, request}, cb) => { ... }
(Use `node --trace-deprecation ...` to show where the warning was created)


 ERROR #98123  WEBPACK

Generating development SSR bundle failed

getResolve is not a function


 ERROR #98123  WEBPACK

Generating development SSR bundle failed

getResolve is not a function


 ERROR #98123  WEBPACK

Generating development SSR bundle failed

getResolve is not a function


 ERROR #98123  WEBPACK

Generating development SSR bundle failed

getResolve is not a function


 ERROR #98123  WEBPACK

Generating development SSR bundle failed

getResolve is not a function


 ERROR #98123  WEBPACK

Generating development SSR bundle failed

getResolve is not a function

not finished Building development bundle - 0.618s

React-Native image element doesn't seem to be functional

Hi,
Thank you for creating this plugin, it's really helpful and all seems to be running smoothly.
Using the Image element with the source prop, however, doesn't seem to be working. Is this a known bug or an issue on my end?

In the example below, 'Hello' will render but Image will not:
<View> <Text>Hello</Text> <Image style={styles.heroImage} source ={require('../assets/Logo.png')}/> </View>

Error: The project entry file could not be resolved.

Now when usinjg the @expo/webpack-config, we get a warning

Error: The project entry file could not be resolved. Please either define it in the `package.json` (main), `app.json` (expo.entryPoint), create an `index.js`, or install the `expo` package.

A workaround is to just put an empty index.js at the root of your project, or yarn add expo (even if you won't use it)

This gatsby plugin (and thus the @expo/webpack-config) can be used with plain RNW. User might not always want to use Expo SDK web apis.

I see 2 solutions:

  • @expo/webpack-config should allow to bypass this warning (I guess it can make sense for NextJS integration too)
  • This gatsby plugin could fallback to another webpack config if expo dependency is not found (seems not ideal, as expo config does some useful things we want to keep)

@EvanBacon any idea how this should be handled?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.