Closed f-elix closed 2 years ago
Hi,
I had this problem too, npm i -D stream
should fix it.
I think the last time I encountered this, it was because of hidden dependencies in node-fetch
.
e.g. #1925
I had the same issue and installing stream fixed it for me as well...
we will need to make a note of this in the docs for the netlify adapter, no?
Or is this something that can be fixed in kit?
This may be related to https://github.com/rollup/plugins/issues/1004, so perhaps this will be fixed when https://github.com/rollup/plugins/pull/1005 is merged and then Vite is upgraded to use it
Adding npm i -D stream
does solve the problem in netlify build.
But when I use SSR and access my application, got
{
"errorType": "ReferenceError",
"errorMessage": "fetch is not defined",
"trace": [
"ReferenceError: fetch is not defined",
" at get_hooks (/var/task/functions/render/index.js:31627:41)",
" at init (/var/task/functions/render/index.js:31503:17)",
" at Object.<anonymous> (/var/task/functions/render/index.js:33889:1)",
" at Module._compile (internal/modules/cjs/loader.js:999:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
" at Module.load (internal/modules/cjs/loader.js:863:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
" at Module.require (internal/modules/cjs/loader.js:887:19)",
" at require (internal/modules/cjs/helpers.js:74:18)",
" at Object.<anonymous> (/var/task/render.js:1:18)"
]
}
Using @sveltejs/kit@1.0.0-next.176 and svelte@3.43.0.
Any help? Thank you.
if possible try to update your netlify node version to 16, where stream/web is available
@tomatrow Installing stream
fixed it!
I'd rather not have this in my dependencies but it's not that big of a problem if it makes things work.
Thanks to all for the answers!
I got a fix into @rollup/plugin-commonjs
and upgraded @sveltejs/kit
and vite
to use it. Can you try upgrading to 1.0.0-next.180
which I just released to see if it helps?
@benmccann Still happening for me with 1.0.0-next.180
.
if possible try to update your netlify node version to 16, where stream/web is available
added
"engines": {
"node": ">=16"
}
Failed on node16 on netlify.
Also tried 1.0.0-next.180 still fails - installing stream for now.
Has there been any progress on this bug?
Got it working with the following netlify.toml
[build]
command = "npm run build"
publish = "build/publish/"
functions = "build/functions/"
environment = { NODE_VERSION = "14.17.5" }
[dev]
command = "svelte-kit dev"
[functions]
directory = "netlify/functions"
node_bundler = "esbuild"
After a few hours of research and struggling, and a fair number of failed attempts.
Docs: https://docs.netlify.com/configure-builds/file-based-configuration/
What worked for me was specifying the node_bundler
to esbuild
, in place of the default value of zisi
documented for Netlify functions.
[functions]
node_bundler = "esbuild"
The entire config file consider the default values for the build
command and node version 14.18.0.
[build]
command = "npm run build"
publish = "build/"
[context.production]
environment = { NODE_VERSION = "14.18.0" }
[functions]
node_bundler = "esbuild"
Thank you @justingolden21 for the example 👍
Update: I'm using the kit in version 1.0.0-next.180
Perhaps the issue should be re-opened @benmccann? Sorry to bother you specifically, but you seem the most relevant person.
In case anyone else runs into trouble deploying Kit to Netlify, the source of my mysterious show-stopping deploy error missing stream.json:
The problem was with the netlify.toml
file I was using.
Old, bad, copy-pasted from outdated tutorial (creates stream error)
[build]
command = "npm run build"
publish = "build/"
functions = "functions/"
New, works
[build]
command = "npm run build"
publish = "build"
[dev]
command = "svelte-kit dev"
[functions]
directory = "netlify/functions"
node_bundler = "esbuild"
Works!
175 is the version that upgrades to node-fetch 3.0 final, which pulls in fetch-blob, relying on stream. https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md#patch-changes-7
Here's the contents of the relevant section of .netlify/functions-internal/__render.js
var init_install_fetch = __esm({
"node_modules/@sveltejs/kit/dist/install-fetch.js"() {
init_shims();
import_http = __toModule(require("http"));
import_https = __toModule(require("https"));
import_zlib = __toModule(require("zlib"));
import_stream = __toModule(require("stream"));
import_util = __toModule(require("util"));
import_crypto = __toModule(require("crypto"));
import_url = __toModule(require("url"));
commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
src = dataUriToBuffer;
dataUriToBuffer$1 = src;
ponyfill_es2018 = { exports: {} };
It seems like a bug on Netlify's side that upgrading to Node 16 doesn't fix this because stream
is provided by the Node API there: https://nodejs.org/api/stream.html#stream_stream
I filed a bug with them: https://github.com/netlify/zip-it-and-ship-it/issues/743
Hmm. I guess my fix to @rollup/plugin-commonjs
didn't work in this particular scenario as it did in some others because it's esbuild that's hoisting the import this time around. If we're able to turn the adapters into Vite plugin and get rid of esbuild that possibly would fix this. Though I'm not sure exactly what Netlify is trying to do, so there's a pretty decent chance it'd still fail even if we took esbuild out of the loop. This definitely seems like a Netlify bug, so hopefully they'll fix it: https://github.com/netlify/zip-it-and-ship-it/issues/743
Hmm, tricky. Jamstack, much as I love it, seems to yield some brittleness in the deploy part.
There's a PR out that would fix this issue: https://github.com/dependents/node-precinct/pull/88
This is now working. Existing projects will need to "clear cache and deploy"
Still getting the error with Node 16, Latest SvelteKit, added stream manually (v0.02), added netlify.toml. Just get the error
Error message
9:08:52 AM: A Netlify Function failed to require one of its dependencies.
9:08:52 AM: Please make sure it is present in the site's top-level "package.json".
9:08:52 AM: In file "/opt/build/repo/.netlify/functions-internal/render.js"
9:08:52 AM: Cannot find module './llhttp/llhttp_simd.wasm.js' from '/opt/build/repo/.netlify'
Was so excited about trying SvelteKit but not being able to rollout to Netlify is a pain.
Still getting the error with Node 16, Latest SvelteKit, added stream manually (v0.02), added netlify.toml. Just get the error
Error message 9:08:52 AM: A Netlify Function failed to require one of its dependencies. 9:08:52 AM: Please make sure it is present in the site's top-level "package.json". 9:08:52 AM: In file "/opt/build/repo/.netlify/functions-internal/render.js" 9:08:52 AM: Cannot find module './llhttp/llhttp_simd.wasm.js' from '/opt/build/repo/.netlify'
Was so excited about trying SvelteKit but not being able to rollout to Netlify is a pain.
I'm also having the same issue, started today.
There's an open issue for that: https://github.com/sveltejs/kit/issues/5337
Describe the bug
Builds now fail on Netlify since version next.175. Local builds still work, and Netlify builds work with version next.174. I have another Sveltekit project that runs on Vercel and I have no build problems there.
I would like to provide more detail but I have no idea what's going on here. I provided the error log below.
Reproduction
This is a reproduction repo: https://github.com/f-elix/sveltekit-netlify-build-fail
It's essentially the Sveltekit demo app with netlify-adapter. I tried to deploy it on Netlify and got the same error as my main project.
Logs
System Info
Severity
blocking an upgrade
Additional Information
No response