Giter VIP home page Giter VIP logo

Comments (3)

hi-ogawa avatar hi-ogawa commented on July 17, 2024 2

I tried to decipher what's happening but unfortunately I couldn't figure out yet where this goes wrong. https://github.com/hi-ogawa/reproductions/tree/main/vitest-5664-mui-emotion-provider

It seems like Vite SSR is fine, so Vitest / Vite-node might be making bad resolution. It could be a bug, so we can leave this issue open.

from vitest.

hi-ogawa avatar hi-ogawa commented on July 17, 2024

As indicated by the warning:

stderr | node_modules/@ emotion/react/dist/emotion-react.esm.js:472:15
You are loading @emotion/react when it is already loaded. Running multiple instances may cause problems. This can happen if multiple versions are used, or if multiple builds of the same version are used.

this is a dual package issue of @emotion/react. The one imported through @mui/material (via NodeJS) and the other from your source code (via Vite/Vitest) are seeing different context singleton.

It looks like NodeJS is loading @emotion/react/dist/emotion-react.cjs.mjs, so you can force Vitest's resolution via alias:
https://stackblitz.com/edit/vitest-dev-vitest-wpfmsa?file=vitest.config.ts

  test: {
    alias: {
      '@emotion/react': path.resolve(
        'node_modules/@emotion/react/dist/emotion-react.cjs.mjs'
      ),
    },
  },

Looking at https://publint.dev/@emotion/[email protected], the package exports is quite complicated, but seems legitimate, so it might be possible that Vite / Vitest's default resolution is doing something wrong.

from vitest.

AlexDroll avatar AlexDroll commented on July 17, 2024

Well as workaround this works but I think it is not good that vite and vitest behave in a different way.
Isn't there a way to force the loading of the correct module on vitest side?

from vitest.

Related Issues (20)

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.