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.

unable to get RNW working with on SSR side

See original GitHub issue

Description

I’m trying to use this plugin with React Native Web.

I’ve verified config below (aliasing RN to RNW) works in vanilla Vite project.

But using with ssr plugin, the alias is not picked up, resulting import error due to trying to import react-native package.

It does seem like this plugin overrides config, so please recommend best approach or necessary fix for getting this working.

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import ssr from 'vite-plugin-ssr/plugin'

const reactNativeWeb = () => ({
  name: 'react-native-web-plugin',
  config: () => ({
    resolve: {
      alias: {
        extensions: [".web.jsx", ".web.js", ".jsx", ".js"],
        "react-native": "react-native-web",
      }
    }
  })
})

export default defineConfig({
  plugins: [
    reactNativeWeb(),
    react(),
    ssr()
  ],
})

Error Stack

RN alias error: 

import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
^^^^^^

SyntaxError: Cannot use import statement outside a module

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Nov 15, 2022

Closing because I think it’s a user land issue that should be fixable.

But if you have evidence that it’s related to vite-plugin-ssr (ideally two reproductions as I described above), then I’m happy to have a look. I’ll reopen then.

(FYI https://brillout.github.io/rules/.)

0reactions
brilloutcommented, Nov 15, 2022

👍 . Btw. contribution much welcome to create a react-native example. I’ll then link it from the docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Example of an SSR RNWeb adaptive/heavily responsive site
Hi there,. At my place of work we have a large RN codebase and have been working hard on the web platform side...
Read more >
Angular Server Side Rendering (SSR) not loading html for ...
I'm experiencing an issue with how my angular app loads. For some reason on viewing the application online regardless of the route, the...
Read more >
The different strategies to building a cross-platform app
The Tamagui and NativeWind ones should work with responsivity and SSR/SEO. But with Tamagui you also get a pre-built component/UI library, plus ...
Read more >
West Side Show Room News - Facebook
Casting Notices, Opportunities, and News for actors, singers, dancers, and performers at The West Side Show Room in Rockford, Illinois.
Read more >
What I Learned Rebuilding My Portfolio With React Native Web
In this article I break down my key take-aways from rebuilding my portfolio app in RNW, and attempt to extrapolate these lessons into...
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