diff --git a/.changeset/lucky-glasses-sell.md b/.changeset/lucky-glasses-sell.md new file mode 100644 index 000000000000..42b2f76974d1 --- /dev/null +++ b/.changeset/lucky-glasses-sell.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-netlify': patch +--- + +Ensure build directory exists before writing \_redirects diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index c68a9be3c037..eaee54986bb1 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -1,5 +1,5 @@ import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'fs'; -import { join, resolve, posix } from 'path'; +import { dirname, join, resolve, posix } from 'path'; import { fileURLToPath } from 'url'; import glob from 'tiny-glob/sync.js'; import esbuild from 'esbuild'; @@ -234,6 +234,7 @@ function generate_lambda_functions({ builder, publish, split, esm }) { if (existsSync('_redirects')) { builder.copy('_redirects', redirect_file); } + builder.mkdirp(dirname(redirect_file)); appendFileSync(redirect_file, `\n\n${redirects.join('\n')}`); }