wasp
wasp copied to clipboard
Solve double installation issue in restructuring
[!NOTE] Could be solved by #1838
[no longer up to date] How to reproduce:
- Checkout
filip-project-install-step
- Go to
waspc/examples/todo-typescript
- Run
rm -r .wasp node_modules package-lock.json migrations; cabal run wasp-cli db migrate-dev -- --name init && cabal run wasp-cli start
- Open the browser, you should see a white screen and a console full of errors caused by a double react installation
How to fix (temporarily):
- Run
./fix
and restart the app (withcabal run wasp-cli start
). This script deletes the redundant react installation and Vite's cache.
Ideas on approaching the issue:
-
How does the SDK resolve React? How does the user's code resolve React? How does our web app's code resolve React? We should figure out who uses which React installation
-
This question is related to the first bullet, but it might make sense to figure out what triggered this behavior now. The problem only appeared after I merged the auth stuff into the restructuring branches.
To compare the old build output with the new output, I recommend:
- Checking out the last commit before the auth merge:
git checkout ea5a4c
- Running
rm -r .wasp node_modules package-lock.json migrations; cabal run wasp-cli db migrate-dev -- --name init && cabal run wasp-cli start
- Comparing the resulting
.wasp
folder with the folder you get when running the same command on the latest commit (here's a good extension for this).
- Checking out the last commit before the auth merge:
Possible solutions:
- Prevent NPM (or Vite) from installing a package if it's already available (i.e., there's a
node_modules
folder higher up the directory tree with the installed package, as is the case for us) - Use NPM workspaces (maybe): https://iws.io/2022/invalid-hook-multiple-react-instances
- ~List
React
as SDK's peerDependency~ - tried it, doesn't work (see here) - Ask Fran Zekan what he thinks
I believe we solved this issues by using the dedupe
option in Vite. There were some build issues afterwards, but they seemed unrelated. I'll let @sodic close this when he thinks it's appropriate
I wouldn't close it until we figure out what's causing those build issues. Since they weren't happening unless we do dedupe
, they probably are related.
Some suggestions from the author of the React plugin for Vite that we use: https://github.com/vitejs/vite-plugin-react-swc/issues/184#issuecomment-1899964854
This issue is not react-specific. For example, if one of our inner dependencies (i.e, package.json files inside web-app and server) specifies prisma/client as a dependency, the runtime resolves to the wrong prisma/client installation and breaks.
We've temporarily avoided this problem by moving all the stuff that depends on prisma/client into sdk/package.json.