Skip to content

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

Closed

Description

@f-elix

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

Activity

  1. tomatrow commented on Sep 29, 2021

    @tomatrow

    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

  2. rchrdnsh commented on Sep 29, 2021

    @rchrdnsh

    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?

  3. benmccann commented on Sep 29, 2021

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

  4. added this to the 1.0 milestone on Sep 29, 2021
  5. niwasmala commented on Sep 30, 2021

    @niwasmala

    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.

  6. f-elix commented on Oct 1, 2021

    @f-elix
    ContributorAuthor

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

  7. benmccann commented on Oct 5, 2021

    @benmccann
    Member

    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?

  8. bekos commented on Oct 6, 2021

    @bekos

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

  9. JohnRSim commented on Oct 6, 2021

    @JohnRSim

    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.

  10. JohnRSim commented on Oct 6, 2021

    @JohnRSim

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

  11. justingolden21 commented on Oct 7, 2021

    @justingolden21

    Has there been any progress on this bug?

  12. justingolden21 commented on Oct 7, 2021

    @justingolden21

    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/

  13. borntofrappe commented on Oct 8, 2021

    @borntofrappe
    Contributor

    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

  14. 4 remaining items

  15. benmccann commented on Oct 12, 2021

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

  16. benmccann commented on Oct 12, 2021

    @benmccann
    Member

    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

  17. benmccann commented on Oct 12, 2021

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

  18. renefournier commented on Oct 13, 2021

    @renefournier

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

  19. benmccann commented on Oct 20, 2021

    @benmccann
    Member

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

  20. benmccann commented on Nov 4, 2021

    @benmccann
    Member

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

  21. samheyman commented on Jul 6, 2022

    @samheyman

    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.

  22. Dabugger commented on Jul 7, 2022

    @Dabugger

    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.

  23. benmccann commented on Jul 7, 2022

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions