Skip to content

Conversation

@benmccann
Copy link
Member

@benmccann benmccann commented Jan 13, 2025

NOTICE: users should add "prepare": "svelte-kit sync" to their projects. preprepare may also be used in favor of prepare, but is not currently supported on all systems. E.g. users of pnpm should prefer prepare until pnpm/pnpm#8989 is merged and release

This solves multiple problems. Firstly, the postinstall script doesn't run on any version of pnpm today because pnpm caches side-effects and they get executed only once ever. Secondly, with pnpm 10 the postinstall scripts of dependencies do not run by default and need to be enabled on a package-by-package basis

@changeset-bot
Copy link

changeset-bot bot commented Jan 13, 2025

🦋 Changeset detected

Latest commit: cee9a29

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-kit-13304-svelte.vercel.app/

this is an automated message


const cwd = process.cwd();

const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? this assumes the vite command is always run with cwd being the sveltekit app.
As a user i'd also prefer if this was silencable without adding a prepare script.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run it any other way? I remember those PRs trying to allow you to configure the cwd and you commenting that we should reject those

Any ideas on how you'd want to silence it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for silencing it i guess going through onwarn would help.

One way to avoid false positives at least would be to check if @sveltejs/kit was in devDependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding control over cwd this was a genuine question. If we deem it appropriate to have this as a constraint (i think other parts of our code might also rely on it) then this method here is the easiest. If not, we'd have to go through vite root in configResolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I put it through onwarn

This is SvelteKit, so you kind of have to have @sveltejs/kit in your dependencies. I'm not sure what such a check would be looking for

I added an explicit reference to cwd so that if we ever do make cwd configurable we won't overlook this as something to check - though it doesn't sound like we'll be doing that so I'm not too worried about it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All that the prepare script is supposed to be doing is run sync, which will just avoid the annoying warning. People having existing projects will not see that run anyway, and people with new projects going through the CLI will have the prepare script setup for them. So I would just remove that warning entirely. It's not like there's any harm in not running sync in advance other than this Vite warning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. I removed the warning and instead filed #13326 and added extra details to the changeset

@leonidaz
Copy link

leonidaz commented Jan 13, 2025

interesting that prepare is still mentioned in the documentation:

`svelte-kit sync` creates the `tsconfig.json` and all generated types (which you can import as `./$types` inside routing files) for your project. When you create a new project, it is listed as the `prepare` script and will be run automatically as part of the npm lifecycle, so you should not ordinarily have to run this command.

@Conduitry
Copy link
Member

Installing a package from Git does run its prepare script (unlike installing it from a registry or from a tarball). I don't know whether that's going to have some impact on this. I guess if someone intended their library to be consumed that way, they'd change their prepare script to run npm run package instead anyway, and we wouldn't need to worry about this?

@dominikg
Copy link
Member

we could try to detect presence of svelte-package in devDependencies and not log then.

Alternatively if this didn't work in pnpm for a long time and we update the template for new apps, do we really need this warning? It'll sort itself after first call of vite dev or vite build so it is a nuisnance at best. As long as me make an FAQ entry discoverable by the error message text, isn't that enough?

@benmccann
Copy link
Member Author

Installing a package from Git does run its prepare script (unlike installing it from a registry or from a tarball). I don't know whether that's going to have some impact on this.

Hmm. That would affect Svelte libraries published via git for consumption in non-SvelteKit projects. I guess in that case they can just remove the prepare script and live with the warning until we remove it after a migration period. Not ideal, but hopefully not very common

I guess if someone intended their library to be consumed that way, they'd change their prepare script to run npm run package instead anyway, and we wouldn't need to worry about this?

I expect they'd still want svelte-kit sync to run for local development, but could just rely on dev doing it. They wouldn't necessarily change their prepare script. The template has:

"prepublishOnly": "npm run package",

Alternatively if this didn't work in pnpm for a long time and we update the template for new apps, do we really need this warning? It'll sort itself after first call of vite dev or vite build so it is a nuisnance at best. As long as me make an FAQ entry discoverable by the error message text, isn't that enough?

It is true that missing it doesn't break anything. But it's a nicer experience with it present and I feel most people aren't going to know they should add it now or even take the time to Google why all of a sudden they're getting a new warning. It feels a lot nicer if we can help people migrate

@dummdidumm dummdidumm merged commit e541a40 into main Jan 17, 2025
14 checks passed
@dummdidumm dummdidumm deleted the prepare branch January 17, 2025 09:48
@github-actions github-actions bot mentioned this pull request Jan 17, 2025
@benmccann benmccann changed the title feat: remove the postinstall script in favor of template prepare script feat: remove the postinstall script in favor of template preprepare script Jan 17, 2025
@ryansobol
Copy link

ryansobol commented Jan 17, 2025

Strange, I'm still seeing the warning, despite trying both "prepare" and "preprepare". What am I doing wrong?

$ pnpm -v
10.0.0
$ grep '@sveltejs/kit' package.json
                "@sveltejs/kit": "^2.16.0",
$ grep prepare package.json
                "preprepare": "svelte-kit sync",
                "prepare": "svelte-kit sync",
$ rm -rf .svelte-kit/
$ pnpm run dev

> admin-platform@0.0.1 dev /Users/ryansobol/Projects/ryansobol/admin-platform
> 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 v6.0.7  ready in 983 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

@cloudymeatball
Copy link

Is this something all existing kit projects should add, or just for ones expected to use / potentially use pnpm 10?

@benmccann
Copy link
Member Author

@ryansobol it looks like a bug in pnpm. Hopefully pnpm/pnpm#8989 should fix it

@cloudymeatball all existing kit projects should add that line to their package.json

@fromaline
Copy link

fromaline commented Jan 27, 2025

I get this error after upgrading to @sveltejs/kit@2.16.0, is it somehow related to the postinstall script?

error during build:
[vite-plugin-sveltekit-compile] ENOENT: no such file or directory, open '/Users/username/Personal/project/.svelte-kit/output/server/undefined'
    at Object.readFileUtf8 (node:internal/fs/sync:25:18)
    at Object.readFileSync (node:fs:441:19)
    at file:///Users/username/Personal/project/node_modules/@sveltejs/kit/src/exports/vite/build/build_server.js:56:24
    at Array.forEach (<anonymous>)
    at build_server_nodes (file:///Users/username/Personal/project/node_modules/@sveltejs/kit/src/exports/vite/build/build_server.js:48:5)
    at Object.handler (file:///Users/username/Personal/project/node_modules/@sveltejs/kit/src/exports/vite/index.js:919:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PluginDriver.hookParallel (file:///Users/username/Personal/project/node_modules/rollup/dist/es/shared/node-entry.js:19858:17)
    at async file:///Users/username/Personal/project/node_modules/rollup/dist/es/shared/node-entry.js:20860:13
    at async catchUnfinishedHookActions (file:///Users/username/Personal/project/node_modules/rollup/dist/es/shared/node-entry.js:20282:16)

@benmccann benmccann changed the title feat: remove the postinstall script in favor of template preprepare script feat: remove the postinstall script in favor of template prepare script Jan 29, 2025
@benmccann
Copy link
Member Author

I get this error after upgrading to @sveltejs/kit@2.16.0, is it somehow related to the postinstall script?

No. It would be related to #13068

@fromaline
Copy link

@benmccann, thanks a lot! Removing inlineStyleThreshold resolved the issue for me!

thokra-nav added a commit to nais/console-frontend that referenced this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants