wasp icon indicating copy to clipboard operation
wasp copied to clipboard

Solve double installation issue in restructuring

Open sodic opened this issue 1 year ago • 4 comments

[!NOTE] Could be solved by #1838

[no longer up to date] How to reproduce:

  1. Checkout filip-project-install-step
  2. Go to waspc/examples/todo-typescript
  3. Run rm -r .wasp node_modules package-lock.json migrations; cabal run wasp-cli db migrate-dev -- --name init && cabal run wasp-cli start
  4. 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 (with cabal 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:

    1. Checking out the last commit before the auth merge: git checkout ea5a4c
    2. Running rm -r .wasp node_modules package-lock.json migrations; cabal run wasp-cli db migrate-dev -- --name init && cabal run wasp-cli start
    3. 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).

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

sodic avatar Jan 17 '24 14:01 sodic

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

infomiho avatar Jan 18 '24 12:01 infomiho

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.

sodic avatar Jan 18 '24 14:01 sodic

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

infomiho avatar Jan 19 '24 08:01 infomiho

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.

sodic avatar Jan 21 '24 11:01 sodic