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

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 24 (12 by maintainers)

Commits related to this issue

Most upvoted comments

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

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!

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

There’s a PR out that would fix this issue: https://github.com/dependents/node-precinct/pull/88

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

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

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/