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

[Sveltekit v next.175+ with Netlify adapter] Cannot find module 'stream/package.json' #2523

Closed
f-elix opened this issue Sep 29, 2021 · 24 comments

Comments

@f-elix
Copy link
Contributor

f-elix commented Sep 29, 2021

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

11:36:32 AM: ────────────────────────────────────────────────────────────────
11:36:32 AM:   Dependencies installation error                               
11:36:32 AM: ────────────────────────────────────────────────────────────────
11:36:32 AM: ​
11:36:32 AM:   Error message
11:36:32 AM:   A Netlify Function failed to require one of its dependencies.
11:36:32 AM:   Please make sure it is present in the site's top-level "package.json".

11:36:32 AM:   In file "/opt/build/repo/.netlify/functions-internal/__render.js"
11:36:32 AM:   Cannot find module 'stream/package.json'
11:36:32 AM:   Require stack:
11:36:32 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/resolve.js
11:36:32 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/index.js
11:36:32 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/main.js
11:36:32 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
11:36:32 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/commands/get.js
11:36:32 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/core/main.js
11:36:32 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/core/bin.js
11:36:32 AM: ​

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 24.27 GB / 39.76 GB
  Binaries:
    Node: 14.15.5 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - C:\Program Files\nodejs\yarn.CMD
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1023.0), Chromium (94.0.992.31)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @sveltejs/adapter-netlify: ^1.0.0-next.31 => 1.0.0-next.31
    @sveltejs/kit: ^1.0.0-next.175 => 1.0.0-next.175
    svelte: ^3.43.0 => 3.43.0

Severity

blocking an upgrade

Additional Information

No response

@tomatrow
Copy link

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

@rchrdnsh
Copy link

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?

@benmccann
Copy link
Member

This may be related to rollup/plugins#1004, so perhaps this will be fixed when rollup/plugins#1005 is merged and then Vite is upgraded to use it

@benmccann benmccann added this to the 1.0 milestone Sep 29, 2021
@niwasmala
Copy link

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)"
  ]
}

image

Using @sveltejs/kit@1.0.0-next.176 and svelte@3.43.0.

Any help? Thank you.

@dominikg
Copy link
Member

if possible try to update your netlify node version to 16, where stream/web is available

@f-elix
Copy link
Contributor Author

f-elix commented Oct 1, 2021

@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!

@benmccann
Copy link
Member

benmccann commented Oct 5, 2021

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?

@bekos
Copy link

bekos commented Oct 6, 2021

@benmccann Still happening for me with 1.0.0-next.180.

@JohnRSim
Copy link

JohnRSim commented Oct 6, 2021

if possible try to update your netlify node version to 16, where stream/web is available

added

  "engines": {
    "node": ">=16"
  }

image
Failed on node16 on netlify.

@JohnRSim
Copy link

JohnRSim commented Oct 6, 2021

Also tried 1.0.0-next.180 still fails - installing stream for now.

@justingolden21
Copy link

Has there been any progress on this bug?

@justingolden21
Copy link

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/

@borntofrappe
Copy link
Contributor

borntofrappe commented Oct 8, 2021

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

@borntofrappe

This comment has been minimized.

@renefournier
Copy link

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!

colbywhite added a commit to sameappdiffframework/rap-quotes-sveltekit that referenced this issue Oct 10, 2021
CrzyMan added a commit to CrzyMan/portfolio-svelte-netlify that referenced this issue Oct 11, 2021
@benmccann
Copy link
Member

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

@benmccann
Copy link
Member

benmccann commented Oct 12, 2021

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: netlify/zip-it-and-ship-it#743

@benmccann
Copy link
Member

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: netlify/zip-it-and-ship-it#743

@renefournier
Copy link

Hmm, tricky. Jamstack, much as I love it, seems to yield some brittleness in the deploy part.

@benmccann
Copy link
Member

There's a PR out that would fix this issue: dependents/node-precinct#88

rahulsivalenka pushed a commit to rahulsivalenka/rahulsivalenka-dev that referenced this issue Oct 30, 2021
This is to fix the issue in netlify build:
"Dependencies installation error"
Ref: sveltejs/kit#2523 (comment)
benaltair added a commit to benaltair/point that referenced this issue Nov 2, 2021
@benmccann
Copy link
Member

This is now working. Existing projects will need to "clear cache and deploy"

@samheyman
Copy link

samheyman commented Jul 6, 2022

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.

@Dabugger
Copy link

Dabugger commented Jul 7, 2022

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.

@benmccann
Copy link
Member

There's an open issue for that: #5337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests