-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Error: Cannot find module use-sync-external-store/shim/with-selector
#379
Comments
hm, i haven't seen this before. undoubtedly it's related to the v4 of zustand, which introduces |
Having the same problem, can't figure out a workaround |
+1 having the same problem, works in the example but not in our implementation, can't find a work around |
Ran into the same issue with Next.js. I found importing dynamically with no SSR (as in the example) solved this for me. |
Did you try running example yourselves (on localhost)? It’s strange, because official example doesn’t work for me as well as my own implementation. |
Using dynamic imports like the example fixed this problem for me. Thank you for the workaround until we can have a more robust solution! |
This works for me. bypass this error just like you. |
Is it possible to correct this issue ? this is very annoying @NoahZinsmeister |
This problem is still not working on build mode. dynamic loading is working on "yarn dev" only. how to solve it? |
@mauver @BowgartField I believe I've got a solution! Strange to see this work but in import { useDebugValue } from 'react';
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'; Add a import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'; Never great editing stuff in `/node_modules/ but hopefully this works for ya'll as a temporary fix. |
Maybe it's the version of Zustand used here? It should be added to the zustand library |
For those who use
It will force With this or #379 (comment), there's a weird log in nextJS console:
@mmoderwell can you confirm this ? Or those are something on my own. |
@AzzouQ it seems like |
Indeed, Adding .js or using resolution work without dynamic but only in |
I already tried this but whitout sucess :/ |
thank you all guys. I solved by adding the zustand package on my package.json. |
@sinnrrr It seems like it also occur when using |
Bump. How does the library's ONE dependency break? 😆 |
From what I have understand, it's not related to
|
Right. But web3-react takes that version of zustand as a dependency. Even when not doing any SSR the library is unusable in NextJS. If that is the intended behavior, the library should be renamed to @web3-react-but-not-for-nextjs or something. 😄 |
@amsheehan please, look at the official example, it uses nextjs, you can try to launch it and look at source code |
I'm actually using some workaround to be able to use those hooks without the inconvenience of importing everything dynamicaly. I've no idea how bad practice it can be tho or what drawback it can have (bad SEO etc etc...), but it seems to work as for now... The main idea is to Will look like this: // HooksProvider.tsx
const HooksProvider: FC = ({ children }) => {
const dispatch = useAppDispatch();
const [isReady, setReady] = useState<boolean>(false);
const priorityConnector = getPriorityConnector(
[metaMask, metaMaskHooks],
[walletConnect, walletConnectHooks],
[network, networkHooks]
);
useEffect(() => {
dispatch(hooksActions.init({ priorityConnector }));
setReady(true);
}, [dispatch, priorityConnector]);
return isReady ? (children as ReactElement) : null;
};
export default HooksProvider; // hooks.slice.ts
import type { PriorityConnector } from 'src/connectors';
export type HooksState = {
priorityConnector: PriorityConnector | undefined;
};
const initialState: HooksState = {
priorityConnector: undefined,
};
const hooksSlice = createSlice({
name: 'hooks',
initialState: initialState,
reducers: {
init: (_state, action: PayloadAction<HooksState>) => action.payload,
reset: () => initialState,
},
});
const stateSelector = createSelector(
({ hooks }: { hooks: HooksState }) => hooks,
(state) => state
);
export const hooksSelectors = {
getPriorityConnector: createSelector(
stateSelector,
(state) => state.priorityConnector as PriorityConnector
),
};
export const { actions: hooksActions, reducer: hooksReducer } = hooksSlice; // pages/index.tsx (could probably be added in _app.tsx with other Provider)
const HooksProvider = dynamic(
() => import('HooksProvider'),
{ ssr: false }
);
const Home: NextPage = () => {
return (
<>
<Head>
{...}
</Head>
<HooksProvider>
{...} // Your app (Header, Body, Footer, or whatever)
</HooksProvider>
</>
);
};
export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
return {
props: { ... },
};
};
export default Home; Then you can use it like this in any children of your Provider export const Component: FC = () => {
const { usePriorityConnector } = useAppSelector(
prioritySelectors.getPriorityConnector
);
const connector = usePriorityConnector();
return (<Text>{getName(connector)}</Text>);
}; 2 improvements could be done with that solution:
|
Another solution without having to change the approach to loading components is to override the dependency. This package forces resolution to a specified version in package-lock.json: https://www.npmjs.com/package/npm-force-resolutions In your main
|
Did you try build?
Because of this above error, building can't be done successfully. |
So, the solution would be to create a PR here to:
That's it? |
This fixes it: #415 The only thing that happens now is the |
It's never been a problem with Zustand in the first place (see #379 (comment)). Importing component dynamically is enough for not having the zustand error, modifying the version won't solve the build problem since it occur with The problem is related to NextJS especially(see #379 (comment)), as this doesn't occur in CRA or else. |
Imports `use-sync-external-store/shim/with-selector.js` (with a `.js` suffix) so that it is correctly resolved by esm bundlers like nextjs. Fixes Uniswap/web3-react#379, which is broken using [4.0.0-beta.1](https://www.npmjs.com/package/zustand/v/4.0.0-beta.1).
Just hit this as well, it would be nice if the example project included the fix for dynamic import so people didn't try it out and have to find this issue. Here's how I "fixed" the error: - import MetaMaskCard from "../components/connectors/MetaMaskCard";
+ import dynamic from "next/dynamic";
+ const MetaMaskCard = dynamic(
+ () => import("../components/connectors/MetaMaskCard"),
+ { ssr: false }
+ ); |
this issue should be fixed by #438 , released under |
the issue is not fixed |
Hello, thanks for such a great package!
I have some troubles with connecting
web3-react
to my application. I'm having the following error:Tried launching the official example under
packages/example
, but also got the same issue.EDIT: I've detected, that it occurs when I'm destructuring from connector hooks (so the problem lies in
initializeConnector
function):The text was updated successfully, but these errors were encountered: