sapper icon indicating copy to clipboard operation
sapper copied to clipboard

Error building when using the --cwd option

Open WHenderson opened this issue 6 years ago • 2 comments
trafficstars

Describe the bug When using the build option "--cwd", sapper fails trying to save the launcher "index.js". The code for writing the launcher fails to take into account the cwd option and instead tries to write to an output folder which does not exist.

Logs / Reproduction sapper build test-output --cwd functions --src ../src --routes ../src/routes ... > ENOENT: no such file or directory, open 'C:\Code\OwnPoC\poc-sapper\test-output\index.js' Error: ENOENT: no such file or directory, open 'C:\Code\OwnPoC\poc-sapper\test-output\index.js' at Object.openSync (fs.js:448:3) at Object.writeFileSync (fs.js:1210:35) at prog.command.describe.option.option.option.option.option.option.option.option.example.action (C:\Code\OwnPoC\poc-sapper\node_modules\sapper\dist\cli.js:588:7)

** Resolution ** In cli.js, replace const launcher = path.resolve(dest, 'index.js'); with const launcher = path.resolve(opts.cwd, dest, 'index.js'); to take account of the cwd option.

Information about your Sapper Installation: Sapper v0.27.9

Severity The only workaround for this requires hacking the mentioned file or forking the entire project.

Additional context The objective for using the command line options above is to have sapper build correctly for use with google cloud functions. The desired structure for google cloud functions is

Path Description
/functions/ cloud functions base
/functions/index.js cloud functions scaffold. This creates the primary entry point into the sapper express app
/functions/rollup.config.js clone of /rollup.config.js because we changed the cwd and no command line option exists to reference the original
/functions/test-output/ The built sapper output

Note that everything sapper builds for the server needs to load files relative to /functions as that is the root as far as cloud functions are concerned. No other folders will be accessible. This means that build_dir needs to be "test-output" and not "functions/test-output" which leads to all the headaches around cwd/src/routes etc.

Thanks in advance, Sapper and Svelte are awesome!

WHenderson avatar Oct 02 '19 00:10 WHenderson

I'm having a similar problem linked here https://github.com/sveltejs/sapper/issues/1074.

Currently working on a fix.

mikeparisstuff avatar Jan 29 '20 18:01 mikeparisstuff

I made a pull request which should solve this problem. See https://github.com/sveltejs/sapper/pull/1584

floratmin avatar Oct 03 '20 08:10 floratmin