kit icon indicating copy to clipboard operation
kit copied to clipboard

`svelte-kit sync` doesn't run everytime on postinstall for pnpm

Open brian14708 opened this issue 1 year ago • 5 comments

Describe the bug

After following the instruction

`svelte-kit sync` now runs on "postinstall" — please remove the "prepare" script from your package.json

Sometimes pnpm run check fails in a clean workspace (git clean / CI).

I believe it has something to do with pnpm's side-effects-cache. It seems to fixed after disabling side-effects-cache in .npmrc

Reproduction

npm create svelte@latest test-postinstall
cd test-postinstall
pnpm i
rm -rf node_modules .svelte-kit
pnpm i
## no .svelte-kit folder
pnpm run check ## <-- FAIL

Logs

No response

System Info

npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/kit: next => 1.0.0-next.401 
    svelte: ^3.46.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.4

Severity

serious, but I can work around it

Additional Information

No response

brian14708 avatar Aug 01 '22 06:08 brian14708

There are two issues on pnpm repo related to this:

  1. https://github.com/pnpm/pnpm/issues/5002
  2. https://github.com/pnpm/pnpm/issues/1394

Disabling the side-effects-cache globally in users projects may result in extra work. Alternative / workaround would be to ensure that sync is run before check aswell, either by prepending it to the created script: "check":"svelte-kit sync && ... or by check itself inspecting the project and calling sync if it is svelte-kit.

dominikg avatar Aug 01 '22 08:08 dominikg

Just to have you aware, the same applies running pnpm dev just after install with sveltekit-next.401 too with pnpm v7.8.0

npm create svelte@latest test-postinstall
cd test-postinstall
pnpm dev

What you get is:

> vite dev

▲ [WARNING] Cannot find base config file "./.svelte-kit/tsconfig.json" [tsconfig.json]

    tsconfig.json:2:12:
      2 │   "extends": "./.svelte-kit/tsconfig.json",
        ╵              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  VITE v3.0.4  ready in 589 ms

  ➜  Local:   http://127.0.0.1:5173/
  ➜  Network: use --host to expose

Still need to set clearScreen: false to vite.config.js as suggested by @Rich-Harris in #5540 even if it should be fixed by #5563

Adding svelte-kit sync && ... to the dev script works as workaround, for sure.

indaco avatar Aug 02 '22 10:08 indaco

npm create svelte@latest test-postinstall
cd test-postinstall
pnpm dev

that should fail spectacularly. You did not call pnpm install for me

pnpm create svelte@latest pnpm-postinstall
cd pnpm-postinstall
pnpm install
pnpm dev

works without issues. .svelte-kit/tsconfig.json is created during postinstall in pnpm install.

~~do you have vite installed globally by chance?~~


EDIT:

reproducible on second install, which is strange because both installs used cached versions of kit

~/develop/reproductions ❯ cd pnpm-postinstall2
is 📦 v0.0.1 via  v16.16.0 
develop/reproductions/pnpm-postinstall2 ❯ pnpm i
Packages: +153
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are copied from the content-addressable store to the virtual store.
  Content-addressable store is at: /home/dominikg/.local/share/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 184, reused 153, downloaded 0, added 153, done

devDependencies:
+ @sveltejs/adapter-auto 1.0.0-next.64
+ @sveltejs/kit 1.0.0-next.401
+ svelte 3.49.0
+ svelte-check 2.8.0
+ typescript 4.7.4
+ vite 3.0.4
is 📦 v0.0.1 via  v16.16.0 took 3s 
develop/reproductions/pnpm-postinstall2 ❯ pnpm dev

> [email protected] dev /home/dominikg/develop/reproductions/pnpm-postinstall2
> vite dev

▲ [WARNING] Cannot find base config file "./.svelte-kit/tsconfig.json" [tsconfig.json]

    jsconfig.json:2:12:
      2 │   "extends": "./.svelte-kit/tsconfig.json",
        ╵              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  VITE v3.0.4  ready in 202 ms

  ➜  Local:   http://127.0.0.1:5173/
  ➜  Network: use --host to expose

anyways, as Rich mentions below in this case it is a warning. This happens because vite dev parses tsconfig.json before we can run svelte-kit sync as part of it. But unless you use vite.config.ts and somehow reference our generated code in there it should still work fine. On second run of pnpm dev that warning is no longer displayed (until you delete .svelte-kit)

dominikg avatar Aug 02 '22 12:08 dominikg

It's an aside to this issue, but: #5563 only defers specific warnings. It's a band-aid rather than a solution. The warning shown above comes from esbuild — we don't have a way to intercept it (other than monkey-patching console). The real fix would be for Vite to not clear the screen when dev first starts: https://github.com/vitejs/vite/issues/9378

Rich-Harris avatar Aug 02 '22 12:08 Rich-Harris

npm create svelte@latest test-postinstall
cd test-postinstall
pnpm dev

that should fail spectacularly. You did not call pnpm install for me

Simply forgot to transcript pnpm install here but I run it.

Attached is the rec for it

sk-test-postinstall

pnpm create svelte@latest pnpm-postinstall
cd pnpm-postinstall
pnpm install
pnpm dev

works without issues. .svelte-kit/tsconfig.json is created during postinstall in pnpm install.

~do you have vite installed globally by chance?~

No, I do not

EDIT:

reproducible on second install, which is strange because both installs used cached versions of kit

~/develop/reproductions ❯ cd pnpm-postinstall2
is 📦 v0.0.1 via  v16.16.0 
develop/reproductions/pnpm-postinstall2 ❯ pnpm i
Packages: +153
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are copied from the content-addressable store to the virtual store.
  Content-addressable store is at: /home/dominikg/.local/share/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 184, reused 153, downloaded 0, added 153, done

devDependencies:
+ @sveltejs/adapter-auto 1.0.0-next.64
+ @sveltejs/kit 1.0.0-next.401
+ svelte 3.49.0
+ svelte-check 2.8.0
+ typescript 4.7.4
+ vite 3.0.4
is 📦 v0.0.1 via  v16.16.0 took 3s 
develop/reproductions/pnpm-postinstall2 ❯ pnpm dev

> [email protected] dev /home/dominikg/develop/reproductions/pnpm-postinstall2
> vite dev

▲ [WARNING] Cannot find base config file "./.svelte-kit/tsconfig.json" [tsconfig.json]

    jsconfig.json:2:12:
      2 │   "extends": "./.svelte-kit/tsconfig.json",
        ╵              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  VITE v3.0.4  ready in 202 ms

  ➜  Local:   http://127.0.0.1:5173/
  ➜  Network: use --host to expose

anyways, as Rich mentions below in this case it is a warning. This happens because vite dev parses tsconfig.json before we can run svelte-kit sync as part of it. But unless you use vite.config.ts and somehow reference our generated code in there it should still work fine. On second run of pnpm dev that warning is no longer displayed (until you delete .svelte-kit)

indaco avatar Aug 02 '22 12:08 indaco

The solution here is to run svelte-kit sync before check, as happens for new projects after #6037 and #6339

Rich-Harris avatar Aug 27 '22 13:08 Rich-Harris