Skip to content
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

svelte-kit sync #4165

Closed
Rich-Harris opened this issue Mar 1, 2022 · 4 comments · Fixed by #4182
Closed

svelte-kit sync #4165

Rich-Harris opened this issue Mar 1, 2022 · 4 comments · Fixed by #4182
Labels
feature request New feature or request
Milestone

Comments

@Rich-Harris
Copy link
Member

Rich-Harris commented Mar 1, 2022

Describe the problem

In #4120, we introduce generated types, which give you type safety when using params inside pages and endpoints. (In future, we want to extend that to props as well.)

One minor wrinkle is that the types aren't generated until you run svelte-kit dev or svelte-kit build, which means that if you were to (for example) typecheck in CI before building the app, it would fail.

Describe the proposed solution

It would be good to collate all the work that takes the filesystem as input (i.e. generating manifest.js, Root.svelte and now the route-level types) into a new function — let's call it sync — and expose it via the CLI as svelte-kit sync. (Open to alternative names but this one seems good enough to me.)

We could then add this to the default template as a postinstall script:

// package.json
"scripts": {
  // ...
  "postinstall": "svelte-kit sync"
}

Importance

would make my life easier

@bluwy bluwy added the feature request New feature or request label Mar 2, 2022
@mquandalle
Copy link

Small note: I think it is generally preferable to use NPM prepare instead of postinstall for this kind of script, because if the package.json ends up being published on npm (for instance after using svelte-kit package) then the postinstall script will be run after any user install the package. In this case svelte-kit sync should only be used at dev time or before build, not on all users machines.

@xpat
Copy link

xpat commented Mar 12, 2022

My bad: I see "prepare": "svelte-kit sync" is used instead of "postinstall" in my package-json. But my error still remains.

Is my error related to this issue? I installed the skeleton version of kit. I have a svelte.config.js, adapted for node as usual (I've gotten this deployment to work for at least six other domains, the last one a little over a week ago). The only thing that immediately jumps out at me is that my package.json didn't have this:

// package.json
"scripts": {
  // ...
  "postinstall": "svelte-kit sync"
}

(But even if I manually add that package, I get the same error.)

~/sveltekitprod$ npm install

01-dev-cleva@0.0.1 postinstall
svelte-kit sync

You need to create a svelte.config.js file. See https://kit.svelte.dev/docs/configuration
at load_config (file:///home/patrouch/sveltekitprod/node_modules/@sveltejs/kit/dist/cli.js:779:9)
at file:///home/patrouch/sveltekitprod/node_modules/@sveltejs/kit/dist/cli.js:1001:25
at o.parse (/home/patrouch/sveltekitprod/node_modules/sade/lib/index.js:1:3402)
at file:///home/patrouch/sveltekitprod/node_modules/@sveltejs/kit/dist/cli.js:1009:6
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
npm ERR! code 1
npm ERR! path /home/patrouch/sveltekitprod
npm ERR! command failed
npm ERR! command sh -c svelte-kit sync

npm ERR! A complete log of this run can be found in:
npm ERR! /home/patrouch/.npm/_logs/2022-03-12T16_02_47_502Z-debug-0.log

Removing "prepare": "svelte-kit sync" from package.json (and issuing the run build command locally, etc.) solved my problem.

@rmontgomery429
Copy link

rmontgomery429 commented Mar 17, 2022

A side effect of this change is that you used to be able to run something like this in a Dockerfile:

COPY package.json package-lock.json ./
RUN npm ci

And it would work.

Now, with this prepare script in place, you get this:

=> ERROR [4/6] RUN npm ci                                                                                                                                                  7.8s
------                                                                                                                                                                           
 > [4/6] RUN npm ci:                                                                                                                                                             
7.504                                                                                                                                                                         
7.504 > example@0.0.1 prepare                                                                                                                                                 
7.504 > svelte-kit sync                                                                                                                                                       
7.504                                                                                                                                                                         
7.550 > You need to create a svelte.config.js file. See https://kit.svelte.dev/docs/configuration
7.550     at load_config (file:///app/node_modules/@sveltejs/kit/dist/cli.js:779:9)
7.550     at file:///app/node_modules/@sveltejs/kit/dist/cli.js:1001:25
7.550     at o.parse (/app/node_modules/sade/lib/index.js:1:3402)
7.550     at file:///app/node_modules/@sveltejs/kit/dist/cli.js:1009:6
7.550     at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
7.550     at async Promise.all (index 0)
7.550     at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
7.550     at async loadESM (node:internal/process/esm_loader:88:5)
7.550     at async handleMainPromise (node:internal/modules/run_main:61:12)
7.558 npm ERR! code 1
7.558 npm ERR! path /app
7.559 npm ERR! command failed
7.559 npm ERR! command sh -c svelte-kit sync

If I remove the prepare script it works again. 😢

If I add the svelte.config.js to the COPY line it gets further but still errors:

=> ERROR [4/6] RUN npm ci                                                                                                                                                  7.6s
------                                                                                                                                                                           
 > [4/6] RUN npm ci:                                                                                                                                                             
7.340                                                                                                                                                                         
7.340 > example@0.0.1 prepare                                                                                                                                                 
7.340 > svelte-kit sync                                                                                                                                                       
7.340                                                                                                                                                                         
7.407 > ENOENT: no such file or directory, scandir '/app/src/routes'
7.408     at Object.readdirSync (node:fs:1392:3)
7.408     at walk (file:///app/node_modules/@sveltejs/kit/dist/chunks/sync.js:180:15)
7.408     at create_manifest_data (file:///app/node_modules/@sveltejs/kit/dist/chunks/sync.js:375:2)
7.408     at update (file:///app/node_modules/@sveltejs/kit/dist/chunks/sync.js:981:24)
7.408     at Module.all (file:///app/node_modules/@sveltejs/kit/dist/chunks/sync.js:996:9)
7.408     at file:///app/node_modules/@sveltejs/kit/dist/cli.js:1003:9
7.415 npm ERR! code 1
7.415 npm ERR! path /app
7.416 npm ERR! command failed
7.417 npm ERR! command sh -c svelte-kit sync

Which seems to suggest that it now expects the entire app to be present to install dependencies which is not typically the case in many Dockerfiles which tend to build dependencies first and then copy source code into the container.

@Conduitry
Copy link
Member

That's a good catch @rmontgomery429 - I've opened #4366.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants