-
Hey all. On the current project I faced the following problem. I tried to create an atom and export it from npm package. And than use it in core to set some value. Tried using the Would appreciate any help. |
Beta Was this translation helpful? Give feedback.
Replies: 17 comments 41 replies
-
That can happen, but not exactly sure how in your case. For the library use case, it's highly recommended to use
Can you reproduce it without the library? Maybe with https://csb.jotai.org |
Beta Was this translation helpful? Give feedback.
-
Hello @dai-shi. Thanks a lot for a such quick reply. https://codesandbox.io/s/red-snow-ffm8xp?file=/src/App.tsx
I met this advices too, but code samples were for jotai v1. Could you please share some minimal code example I could get the main idea? |
Beta Was this translation helpful? Give feedback.
-
Oh, I've just realized that |
Beta Was this translation helpful? Give feedback.
-
Hello @dai-shi. As a result, the problem I shared is mostly related to the way how my projects are built. Eventually it was easier simply set webpack alias for jotai to resolve it from direct node_modules and alway have only one source of library |
Beta Was this translation helpful? Give feedback.
-
I'm getting that warning as well now... though I only have ONE provider at the very top of my NextJS app. |
Beta Was this translation helpful? Give feedback.
-
I'm also having this issue with nextJS, tried the #2061 |
Beta Was this translation helpful? Give feedback.
-
Version 2.3.0 seems to fix it, thanks :) |
Beta Was this translation helpful? Give feedback.
-
Hi, I am having the same error, without using getDefaultStore or something. I am just creating a store with createStore and passing it as a prop to the Provider. I am using jotai with react-native |
Beta Was this translation helpful? Give feedback.
-
I dont fully understand the issue. I have a atoms.tsx where I have two atoms that I use in many places using the useAtom hook. I get this jotai notification and I dont know whether to ignore or if I should take action |
Beta Was this translation helpful? Give feedback.
-
I got this issue issue in a next js application that consume an npm package that also use jotai. I add following config in next.config.js to fix issue const nextConfig = {
webpack: (config, _context) => {
config.resolve.alias['jotai'] = path.resolve(__dirname, 'node_modules/jotai')
return config;
},
} Note that I got a similar issue with multiples instances of React (vercel/next.js#50391) |
Beta Was this translation helpful? Give feedback.
-
I'm facing exactly the same issue and i'm not getting the "Detected multiple Jotai instances` warning We have this setup (pnpm + turborepo)
I want both nextjsApp to be independent, so they have their own provider and store ( ) The sharedReactComponents are built with tsup but they are just like a dummy shared folder. When copy-pasting the components from the shared React Components libs to each of the apps, the atoms do work, however, calling them from the sharedReactComponents is useless as they are empty. SOLVED: |
Beta Was this translation helpful? Give feedback.
-
I'm also experiencing this issue as others say. In my case is even simpler: single project in providerless mode, but I can see the warning triggered from my unit tests execution with UPDATE: I can confirm that:
So, this might do the trick:
if placed in |
Beta Was this translation helpful? Give feedback.
-
in case someone encounters this problem using let mockActualJotai: typeof import("jotai");
jest.mock("jotai", () => {
if (!mockActualJotai) mockActualJotai = jest.requireActual("jotai");
return mockActualJotai;
}); |
Beta Was this translation helpful? Give feedback.
-
This warning also shows in an Expo app in providerless mode. |
Beta Was this translation helpful? Give feedback.
-
I get this warning every time I reload the page in my next.js project (but doesn't go away if I turn off strict mode) |
Beta Was this translation helpful? Give feedback.
-
It is odd, even with the |
Beta Was this translation helpful? Give feedback.
-
For those who come after me! I'm in NextJ2 import { Provider } from 'jotai'
export default function Home() {
return (
<Provider>
<InfiniteCanvas items={items} />
</Provider>
)
} |
Beta Was this translation helpful? Give feedback.
Hello @dai-shi.
Just wanted to share the result of my research and say thanks for your help.
With your answers I started better understand the library plus it helped me with reading its source code.
As a result, the problem I shared is mostly related to the way how my projects are built.
Having two projects: core and feature package I ended up with loading two copies of jotai. Each used
useAtom
from its node_modules.And with custom hook we actually set closure on usage of
useAtom
from one place.Eventually it was easier simply set webpack alias for jotai to resolve it from direct node_modules and alway have only one source of library