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

Cannot run npm ci --prod with adapter-node #4585

Closed
angryziber opened this issue Apr 10, 2022 · 14 comments
Closed

Cannot run npm ci --prod with adapter-node #4585

angryziber opened this issue Apr 10, 2022 · 14 comments
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:create-svelte
Milestone

Comments

@angryziber
Copy link

angryziber commented Apr 10, 2022

Describe the bug

adapter-node says that npm ci --prod should be used to run the build.
However, this command fails

Reproduction

npm ci --prod

Logs

> guidest@0.0.1 prepare
> svelte-kit sync

sh: svelte-kit: not found
npm ERR! code 127
npm ERR! path /app
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!     /root/.npm/_logs/2022-04-10T11_03_37_215Z-debug.log
The command '/bin/sh -c npm ci --prod' returned a non-zero code: 127

System Info

Docker image node:16-alpine

Severity

serious, but I can work around it

Additional Information

Workaround: sed -i '/prepare/d' package.json && npm ci --prod

@Conduitry
Copy link
Member

I think making the prepare script in the template instead be svelte-kit sync || echo might work. It looks like the || syntax works in Windows cmd.exe as well, and echo should be (effectively) a no-op in Unix and Windows. If there's something more elegant than that, I'd love to hear about it. The first thing I tried was true and that unfortunately doesn't work in Windows.

@Conduitry Conduitry added bug Something isn't working pkg:create-svelte p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. labels Apr 11, 2022
@mrkishi
Copy link
Member

mrkishi commented Apr 11, 2022

Since we're mostly interested in the install behavior (since build implicitly runs sync), what about running sync from @sveltejs/kit's postinstall instead?

ps. powershell's echo requires an argument, so it'd need to be at least echo ''.

@Conduitry
Copy link
Member

I tried this from powershell and the script was still run with cmd.exe. I don't know whether there's some configuration that would have made that work differently.

Having it be in Kit's postinstall would be another option, and that would have been my fallback solution if I couldn't find a cross-platform thing to do in the prepare script, but I imagine it would be more moving pieces.

@dominikg
Copy link
Member

When exactly should sync run.

Using the prepare lifecycle seems inappropriate for it given it is called during multiple different phases and run in the background since npm@7 . There may be differences in behavior between package managers too,

https://docs.npmjs.com/cli/v8/using-npm/scripts#life-cycle-scripts

Using postinstall is less invasive than prepare, but is relying on pre/post hooks, which may not be executed. ( due to --ignore-scripts cli flag, pnpm onlyBuiltDependencies option etc).

So if something relies on sync being run before it needs to check that (validate expected files to exist / hash matching) anyways.

@mrkishi
Copy link
Member

mrkishi commented Apr 11, 2022

@Conduitry I don't know what's the configuration or combination of shell and package manager required to trigger it, but this is what I get on pwsh v7.2.2:

F:\projects\svelte\repros\my-app (succeeded in 8ms)
❯ pnpm install --prod --frozen-lockfile
Lockfile is up-to-date, resolution step is skipped
Already up-to-date

devDependencies: skipped

> my-app@0.0.1 prepare F:\projects\svelte\repros\my-app
> svelte-kit sync || echo

svelte-kit: The term 'svelte-kit' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

cmdlet Write-Output at command pipeline position 1
Supply values for the following parameters:
InputObject:

@dominikg sync is already run on dev/build/package. The reason for doing it on prepare was to get it to run right after installation so that you wouldn't get errors about the missing generated tsconfig.json until first build, so I don't think it'd be too bad for it to be skippable.

@Conduitry
Copy link
Member

I agree that erring on the side of not running sync is probably preferable.

Having a postinstall in @sveltejs/kit would also get run when installing dependencies in a checkout of this repo, so we'd need to make sure we made that a no-op in that case. I'm not sure what the CWD is when postinstall is run in various cases.

We would potentially need to worry about making postinstall a no-op when installing this repo's dependencies, on finding the directory containing svelte.config.js when postinstall is run as part of installing Kit to a user's app, and on running svelte-kit sync with the appropriate CWD.

@mrkishi
Copy link
Member

mrkishi commented Apr 11, 2022

In theory cwd is at the root of the current project, so checking for svelte.config.js would indeed be a simple option... In practice, I'm seeing different behavior on pnpm (though perhaps because I was testing with a .tar.gz instead of a published package).

We do have access to INIT_CWD however, and that seems to behave consistently between the big three.

@johann-taberlet

This comment was marked as off-topic.

@dominikg
Copy link
Member

As a workaround, remove the prepare script from package.json. This can lead to errors after updating sveltekit until after you executed svelte-kit sync.

It is automatically called by svelte-kit dev and svelte-kit build so the worst thing that should happen are some red squigglies in your IDE

@Rich-Harris Rich-Harris added this to the 1.0 milestone May 17, 2022
@benmccann

This comment was marked as resolved.

@Rich-Harris

This comment was marked as resolved.

@benmccann
Copy link
Member

Vite tries to read the tsconfig.json upfront in order to bundle the config file. I looked at making Vite bundle the config file only if it's .ts, but it's not that simple because it uses the esbuild output to figure out what the config file dependencies are and I believe watch them to tell if the config file needs to be reloaded. So maybe easier to try to do something just on our side...

I was going to say I'm not sure how postinstall would help anything, but I guess it would because @sveltejs/kit wouldn't get installed with npm ci --prod since it's a devDependency. So yeah, that seems like the best solution to me

@dominikg
Copy link
Member

dominikg commented Jul 31, 2022

The latest version of @sveltejs/kit now uses a postinstall hook to run sync instead of prepare and create-svelte no longer adds a prepare script to new applications.

Please check it out and confirm that it fixes this issue you had

@Conduitry
Copy link
Member

I'm going to go ahead and close this, because it looks good to me now. On a fresh template, npm install && rm -rf node_modules && npm ci --prod works fine. Same thing with the equivalent pnpm commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:create-svelte
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants