Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package use-immer crashes astro #6365

Closed
1 task
RadoslavMarinov opened this issue Feb 24, 2023 · 3 comments · Fixed by #6696
Closed
1 task

Package use-immer crashes astro #6365

RadoslavMarinov opened this issue Feb 24, 2023 · 3 comments · Fixed by #6696
Labels
- P2: nice to have Not breaking anything but nice to have (priority) ecosystem: external External library doesn't work needs response Issue needs response from OP

Comments

@RadoslavMarinov
Copy link

What version of astro are you using?

2.0.6

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the Bug

Importing use-immer into react (tsx) file causes error in the terminal:


import { useImmerReducer } from "use-immer";

const initState = {}
const reducer = (draft, action) => {
  switch(action.type) {      
    default:
      break;
  }
}
const [data, dataDispatch] = useImmerReducer(reducer, initState);

The terminal shows:

12:09:46 AM [astro] reload C:/Users/rojer/code/node/web/astro/rico-12:11:49 AM [astro] reload C:/Users/rojer/code/node/web/astro/rico-astro-website/src/components/xp/immer/immer-reducer.tsx (x9)       
 error   Cannot read properties of undefined (reading 'useImmerReducer')
  File:
    C:\Users\rojer\code\node\web\astro\rico-astro-website\C:\Users\rojer\code\node\web\astro\rico-astro-website\src\components\xp\immer\immer-reducer.tsx:12:29
  Stacktrace:
TypeError: Cannot read properties of undefined (reading 'useImmerReducer')
    at C:/Users/rojer/code/node/web/astro/rico-astro-website/src/components/xp/immer/immer-reducer.tsx:12:29
    at async instantiateModule (file:///C:/Users/rojer/code/node/web/astro/rico-astro-website/node_modules/vite/dist/node/chunks/dep-3007b26d.js:52400:9)

Steps to reproduce

  1. Install use immer npm install immer use-immer
  2. Create react component and add it to a page (make sure it is client side component (client:visible)
    And the server crashes with the above mentioned error

Link to Minimal Reproducible Example

?

Participation

  • I am willing to submit a pull request for this issue.
@MoustaphaDev MoustaphaDev added the ecosystem: external External library doesn't work label Feb 25, 2023
@rishi-raj-jain
Copy link
Contributor

rishi-raj-jain commented Feb 26, 2023

Link to Minimal Reproducible Example
?

Can you add a link to stackblitz as the reproduction repo?

@rishi-raj-jain
Copy link
Contributor

@RadoslavMarinov Here's how you want to run it: https://stackblitz.com/edit/withastro-astro-sfd8r7?file=astro.config.mjs

Basically you need to set the following in astro config:

vite: {
    ssr: {
      noExternal: 'use-immer',
    },
}

cc @MoustaphaDev

@MoustaphaDev
Copy link
Member

Sorry for the late answer @rishi-raj-jain, thanks for investigating, that seems to fix it.

Does that work on your side @RadoslavMarinov?

@MoustaphaDev MoustaphaDev added the needs response Issue needs response from OP label Mar 5, 2023
@matthewp matthewp added the - P2: nice to have Not breaking anything but nice to have (priority) label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) ecosystem: external External library doesn't work needs response Issue needs response from OP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants