Skip to content

Building a for web with vite causes an error when doing a production build #6775

@dannyhw

Description

@dannyhw

Description

When running in dev with vite everything works fine, when I run the build for production for example with npm run build && npm run preview in the repro then I get this error

Initially I ran into this error when working on a new vite framework for storybook but I found the same error present in a users example on the discussions here where it works on dev but fails when serving the static files.

index-DvzMhtGV.js:53 Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at dl (index-DvzMhtGV.js:53:6327)
    at index-DvzMhtGV.js:53:48672
    at Array.forEach (<anonymous>)
    at Dc (index-DvzMhtGV.js:53:48646)
    at Object.a [as worklet] (index-DvzMhtGV.js:53:50781)
    at o (index-DvzMhtGV.js:53:13912)

image

Steps to reproduce

in the repro:

  1. click the terminal
  2. ctrl + c to end the dev server
  3. use the command npm run build && npm run preview to run a preview of the prod build
  4. note the animation fails and open the browser console to see the error

in general:

  1. setup react native web with vite
  2. add reanimated and add the babel plugin to the react plugin's babel config
  3. add an animated component and attempt to animate it
  4. build for prod

Snack or a link to a repository

https://stackblitz.com/edit/vitejs-vite-wcfpnl?file=package.json

same repo from the stack blitz:
https://github.com/dannyhw/vite-reanimated-web-prod-repro

to run here just do
npm install
npm run build && npm run preview

The example code is actually mostly taken from here: #5814

In which disabling strict mode fixes one problem but then in the build theres this new error

Reanimated version

~3.16.3

React Native version

^0.76.3

Platforms

Web

JavaScript runtime

V8

Workflow

None

Architecture

None

Build type

Release app & production bundle

Device

None

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Platform: WebThis issue is specific to webRepro providedA reproduction with a snippet of code, snack or repo is provided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions