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

build command fails as of latest release #250

Closed
antony opened this issue Dec 9, 2020 · 12 comments · Fixed by #252
Closed

build command fails as of latest release #250

antony opened this issue Dec 9, 2020 · 12 comments · Fixed by #252

Comments

@antony
Copy link
Member

antony commented Dec 9, 2020

Describe the bug
The build command refers to something which cannot be found, on a brand new svelte kit project

Logs

 ant@apse  /tmp/wercel   npm run build                                                                                                         19:27:01 

> wercel@0.0.1 build /tmp/wercel
> svelte-kit build

Transforming...
  ⧗ client
  ⧗ server
Optimizing...
  ⧗ client
  ⧗ server
(node:1363910) UnhandledPromiseRejectionWarning: Error: Command failed: node /tmp/wercel/node_modules/snowpack/index.bin.js build --mount.src/routes=/_app/routes --mount.src/setup=/_app/setup --out=.svelte/build/unoptimized/server --ssr
/bin/sh: 1: node: not found

    at ChildProcess.exithandler (child_process.js:303:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:443:11)
    at Socket.emit (events.js:315:20)
    at Pipe.<anonymous> (net.js:674:12)
(node:1363910) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1363910) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> Command failed: node /tmp/wercel/node_modules/snowpack/index.bin.js build --mount.src/routes=/_app/routes --mount.src/setup=/_app/setup --out=.svelte/build/unoptimized/client
/bin/sh: 1: node: not found

Error: Command failed: node /tmp/wercel/node_modules/snowpack/index.bin.js build --mount.src/routes=/_app/routes --mount.src/setup=/_app/setup --out=.svelte/build/unoptimized/client
/bin/sh: 1: node: not found

    at ChildProcess.exithandler (child_process.js:303:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:443:11)
    at Socket.emit (events.js:315:20)
    at Pipe.<anonymous> (net.js:674:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wercel@0.0.1 build: `svelte-kit build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the wercel@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ant/.npm/_logs/2020-12-09T19_27_08_830Z-debug.log

To Reproduce

npm create svelte@next somedir
cd somedir
npm i
npm run build
@Conduitry
Copy link
Member

Conduitry commented Dec 9, 2020

This can be seen when trying to build the example projects in this mono repo as well - pnpm -r build - CI isn't currently failing because that's not trying to build those - pnpm build --filter ./packages Never mind, there is a separate CI job that does attempt to build examples, and is passing on currently latest master. I don't know how that's different from what some people are seeing locally.

@Rich-Harris
Copy link
Member

I wonder if this is related to me bumping the Snowpack version to the 3.0 RC (which I did because I wanted to use the new JS build API, not realising it wasn't actually in the RC yet)? They build fine for me. Do they build for you if you pnpm i?

@Conduitry
Copy link
Member

pnpm install in a fresh clone of this repo isn't trying to build anything for me, successfully or unsuccessfully.

@benmccann
Copy link
Member

CI isn't currently failing because that's not trying to build those - pnpm build --filter ./packages

The CI does build the examples:

- run: pnpm -r build

@Rich-Harris
Copy link
Member

@Conduitry i meant pnpm i and then pnpm build, with up to date deps

@benmccann
Copy link
Member

The build fails on my machine as well (Ubuntu w/ Node 14.8.0). I did pnpm install and then pnpm -r build

@Conduitry
Copy link
Member

Conduitry commented Dec 9, 2020

pnpm install then pnpm build passes for me, but is only trying to build things in packages/. If I run pnpm -r build locally, it also tries to build the examples/, and those do fail.

Edit: I see what pnpm build by itself is apparently doing is pnpm build --filter="@sveltejs/*" --filter="create-svelte", so it's matching by package names rather than by what folder they're in, but the point is that pnpm build is not attempting to build the example projects, which is where I and Ben are having issues - and which also is probably related to Antony being unable to use Kit in a new project, with the same error.

@benmccann
Copy link
Member

I wonder if this is related to me bumping the Snowpack version to the 3.0 RC

Downgrading Snowpack doesn't fix it for me

@Rich-Harris
Copy link
Member

WFM (following @antony's repro instructions), so I'm not going to be much help debugging I'm afraid

@Conduitry
Copy link
Member

I think it's to do with the envs that are now being passed to the execs happening in #240. If I explicitly add in the current PATH, then pnpm -r build works again.

diff --git a/packages/kit/src/api/build/index.js b/packages/kit/src/api/build/index.js
index fe554df..700f242 100644
--- a/packages/kit/src/api/build/index.js
+++ b/packages/kit/src/api/build/index.js
@@ -84,7 +84,8 @@ export async function build(config) {
 	const promises = {
 		transform_client: exec(`node ${snowpack_bin} build ${mount} --out=${UNOPTIMIZED}/client`, {
 			env: {
-				SVELTE_KIT_APP_DIR: config.appDir
+				SVELTE_KIT_APP_DIR: config.appDir,
+				PATH: process.env.PATH
 			}
 		}).then(
 			() => {
@@ -94,7 +95,8 @@ export async function build(config) {
 		),
 		transform_server: exec(`node ${snowpack_bin} build ${mount} --out=${UNOPTIMIZED}/server --ssr`, {
 			env: {
-				SVELTE_KIT_APP_DIR: config.appDir
+				SVELTE_KIT_APP_DIR: config.appDir,
+				PATH: process.env.PATH
 			}
 		}).then(() => {
 			progress.transformed_server = true;

I don't know why this would be system-specific, and I don't know whether the env passed to exec is supposed to completely replace the environment variables it would otherwise be getting.

It might be safest to use process.argv[0] to try to call Node again (rather than doing this pass-PATH-along thing), if we can find a good way to do that that avoids escaping issues and works on Windows.

@Conduitry
Copy link
Member

I don't see anything in Node's docs about automatically merging env vars, so I'm assuming that, if you pass an env object, it replaces the default of process.env. I still don't know why node can still be found on some systems but not others without specifying PATH.

To avoid escaping woes, it might be possible to make use of execFile rather than exec.

@Conduitry
Copy link
Member

I was still getting weird errors about not being able to resolve .js files when trying execFile(process.argv[0]), ...) so I'm back to the environment variable idea. I think I'll just spread process.env into the object we're using. PR incoming.

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 a pull request may close this issue.

4 participants