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

Netlify deploy failing when trying to bundle functions #1859

Closed
felixakiragreen opened this issue Jul 9, 2021 · 11 comments
Closed

Netlify deploy failing when trying to bundle functions #1859

felixakiragreen opened this issue Jul 9, 2021 · 11 comments

Comments

@felixakiragreen
Copy link

Describe the bug
When trying to deploy to Netlify the build fails at the step: "2. Functions bundling"
yarn dev, yarn build, yarn run preview, netlify dev all work with no issues, it only happens when I try to deploy.

Logs

 2. Functions bundling                                         
8:27:53 PM: ────────────────────────────────────────────────────────────────
8:27:53 PM: ​
8:27:54 PM: Packaging Functions from functions directory:
8:27:54 PM:  - render/index.js
8:27:54 PM: ​
8:27:57 PM: ​
8:27:57 PM: ────────────────────────────────────────────────────────────────
8:27:57 PM:   Dependencies installation error                               
8:27:57 PM: ────────────────────────────────────────────────────────────────
8:27:57 PM: ​
8:27:57 PM:   Error message
8:27:57 PM:   A Netlify Function is using "bufferutil" but that dependency has not been installed yet.
8:27:57 PM: ​
8:27:57 PM:   By default, dependencies inside a Netlify Function's "package.json" are not automatically installed.
  There are several ways to fix this problem:
8:27:57 PM:     - Removing your Function's "package.json" and adding the dependencies to the project's top-level "package.json" instead. This is the fastest and safest solution.
8:27:57 PM:     - Running "npm install" or "yarn" inside your Netlify Function in your build command.
8:27:57 PM:     - Adding the following plugin to your "netlify.toml":
8:27:57 PM: ​
8:27:57 PM:   [[plugins]]
8:27:57 PM:   package = "@netlify/plugin-functions-install-core"
8:27:57 PM: ​​
8:27:57 PM:   In file "/opt/build/repo/frontend/functions/render/index.js"
8:27:57 PM:   Cannot find module 'bufferutil'

To Reproduce
I am using the latest versions: (hardcoded into package.json to prevent issues)

"@sveltejs/adapter-netlify": "^1.0.0-next.19",
"@sveltejs/kit": "^1.0.0-next.19",

Expected behavior
I expect it to deploy. I have deployed 3 svelte-kit to netlify, so this isn't my first rodeo. However, they were with previous versions: "@sveltejs/adapter-netlify": "1.0.0-next.12" & "@sveltejs/adapter-netlify": "1.0.0-next.14"`

I tried adding the plugin, but it didn't help.

Stacktraces
If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace

8:27:57 PM: Require stack:
8:27:57 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/resolve.js
8:27:57 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/index.js
8:27:57 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/main.js
8:27:57 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
8:27:57 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/commands/get.js
8:27:57 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/main.js
8:27:57 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/bin.js
8:27:57 PM: ​
8:27:57 PM: Resolved config
8:27:57 PM: build:
8:27:57 PM: base: /opt/build/repo/frontend
8:27:57 PM: command: yarn build
8:27:57 PM: commandOrigin: config
8:27:57 PM: environment:
8:27:57 PM: - NODE_VERSION
8:27:57 PM: publish: /opt/build/repo/frontend/build
8:27:57 PM: publishOrigin: config
8:27:57 PM: functionsDirectory: /opt/build/repo/frontend/functions
8:27:57 PM: redirects:
8:27:57 PM: - from: /*
path: /*
status: 200
to: /.netlify/functions/render

Information about your SvelteKit Installation:

Diagnostics
  • System:
    OS: macOS 11.5
    CPU: (8) arm64 Apple M1
    Memory: 245.63 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
    Binaries:
    Node: 16.1.0 - ~/.nvm/versions/node/v16.1.0/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 7.11.2 - ~/.nvm/versions/node/v16.1.0/bin/npm
    Browsers:
    Chrome: 91.0.4472.114
    Firefox: 80.0
    Safari: 14.1.2
    npmPackages:
    @sveltejs/adapter-netlify: ^1.0.0-next.19 => 1.0.0-next.19
    @sveltejs/kit: ^1.0.0-next.19 => 1.0.0-next.123
    svelte: ^3.34.0 => 3.38.3

Severity
I'm completely blocked from being able to deploy my website. I was really hoping to get it done tonight, but now I'm stuck. I have a hard launch in a week, and I'm stuck.

@felixakiragreen
Copy link
Author

I finally got it working by just adding a bunch of packages to my package.json. It would complain a package was missing, I'd add it, and just repeat until I added all of them. It's weird because they were ones I wasn't using directly, but some dependency was. Like bufferutil, utf-8-validate, ...

@NEO97online
Copy link

@felixakiragreen Please reopen this issue, I believe its something that needs to be addressed. I'm getting the same issue. It appears the Netlify adapter is including some dependencies in the build output which are not being included in the output package.json file.

@austincrim
Copy link

austincrim commented Aug 3, 2021

I'm getting this issue as well. The generated Netlify function (render/index.js) contains a package.json but it only includes this line: {"type":"commonjs"}. My build is failing on the supports-color dependency.

Current workaround: npm run build then comment out the line that is requireing supports-color in the built render/index.js. Then I can deploy locally. Would love to help get this one resolved!

Update
I was able to build and deploy my app to Vercel with no issue. I confirmed that the adapter-vercel build output contained the same supports-color require but it deployed with no problems. Maybe seems like a Netlify problem then?

@brewhousedigital
Copy link

These were all the packages I had to add to get Netlify to be happy

"dependencies": {
    "@lukeed/uuid": "^2.0.0",
    "bufferutil": "^4.0.3",
    "cookie": "^0.4.1",
    "supports-color": "^9.0.2",
    "utf-8-validate": "^5.0.5"
  },

@robhicks
Copy link

I'm having this issue as well, but the problem I'm seeing is different. I have have set the NODE_VERSION to 14. But it appears to be using Node 12 in Functions bundling:

8:54:49 AM: ────────────────────────────────────────────────────────────────
8:54:49 AM:   2. Functions bundling                                         
8:54:49 AM: ────────────────────────────────────────────────────────────────
8:54:49 AM: ​
8:54:49 AM: Packaging Functions from .netlify/functions-internal directory:
8:54:49 AM:  - __render.js
8:54:49 AM: ​
8:54:51 AM: ​
8:54:51 AM: ────────────────────────────────────────────────────────────────
8:54:51 AM:   Internal error during "Functions bundling"                    
8:54:51 AM: ────────────────────────────────────────────────────────────────
8:54:51 AM: ​
8:54:51 AM:   Error message
8:54:51 AM:   Error: readdirp: root argument is required. Usage: readdirp(root, options)
8:54:51 AM: ​
8:54:51 AM:   Error location
8:54:51 AM:   During Functions bundling
8:54:51 AM:       at readdirp (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:262:11)
8:54:51 AM:       at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:276:5
8:54:51 AM:       at new Promise (<anonymous>)
8:54:51 AM:       at Function.readdirpPromise [as promise] (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/readdirp/index.js:274:10)
8:54:51 AM:       at hasFunctionRootFile (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:119:32)
8:54:51 AM:       at lacksNodeModules (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:111:12)
8:54:51 AM:       at getModuleNotFoundMessage (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:50:43)
8:54:51 AM:       at getModuleNotFoundErrorObject (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:41:25)
8:54:51 AM:       at getModuleNotFoundErrorFromZISI (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:91:10)
8:54:51 AM:       at getModuleNotFoundError (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/error.js:27:31)

@outerlook
Copy link

I'm getting the same error as @robhicks, and it doesn't seem to be the same error as the others. Should we open another issue?

@hakimmazouz
Copy link

Can confirm I'm getting the same issue. Build is failing with a supports-color dependency that is unresolved. The package.json in functions-internal just contains {"type":"commonjs"}.

I tried switching the NODE_VERSION env variable in Netlify to 12.20 but no dice.

pushred added a commit to pushred/copy4cash.com that referenced this issue Sep 5, 2021
Adapter has issues: sveltejs/kit#1859

Vercel does not support Yarn 2 for SSR and functions
@swgn
Copy link

swgn commented Sep 21, 2021

I'm now facing the same issue. After many successful deploys, my site is now failing due to missing deps for .netlify/functions-internal. Tried downgrading kit and adapter-netlify etc, nothing seemed to work.

Temporary workaround is to manually install the 'missing' deps until it succeeds, per @felixakiragreen; hardly ideal tho 😏

@Shackless
Copy link

Shackless commented Oct 13, 2021

For me it's even worse because the error log doesn't name any specific packages:

3:27:27 PM: ────────────────────────────────────────────────────────────────
3:27:27 PM:   Dependencies installation error                               
3:27:27 PM: ────────────────────────────────────────────────────────────────
3:27:27 PM: ​
3:27:27 PM:   Error message
3:27:27 PM:   A Netlify Function failed to require one of its dependencies.
3:27:27 PM:   Please make sure it is present in the site's top-level "package.json".
​
3:27:27 PM:   In file "/opt/build/repo/.netlify/functions-internal/__render.js"
3:27:27 PM:   Cannot find module '../lib/utils.js' from '/opt/build/repo/.netlify/functions-internal'

Any ideas how to work around this or what could be missing? I tried adding the packages mentioned here to my package.json but this doesn't resolve the issue.

If I run the build locally, it's successful but I get warnings like these:

> Using @sveltejs/adapter-netlify
 > node_modules/uglify-js/tools/node.js:4:20: warning: "../lib/utils.js" should be marked as external for use with "require.resolve"
    4 │     require.resolve("../lib/utils.js"),
      ╵                     ~~~~~~~~~~~~~~~~~

 > node_modules/uglify-js/tools/node.js:5:20: warning: "../lib/ast.js" should be marked as external for use with "require.resolve"
    5 │     require.resolve("../lib/ast.js"),
      ╵                     ~~~~~~~~~~~~~~~

 > node_modules/uglify-js/tools/node.js:6:20: warning: "../lib/transform.js" should be marked as external for use with "require.resolve"
    6 │     require.resolve("../lib/transform.js"),
      ╵                     ~~~~~~~~~~~~~~~~~~~~~

 > node_modules/uglify-js/tools/node.js:7:20: warning: "../lib/parse.js" should be marked as external for use with "require.resolve"
    7 │     require.resolve("../lib/parse.js"),
...

€: Solved, kind of. I had a src/hooks.ts file that would use the package html-minifier and that caused the issues. Removing the package and script resolved the issue for me. I don't need the workaround packages now either.

@brewhousedigital
Copy link

To anyone still subscribed to this issue, I got in touch with netlify support and they recommended me add this to my netlify.toml file.

[build]
  command = "npm run build"
  publish = "build"

[functions]
  node_bundler = "esbuild"

that last part, node_bundler = "esbuild" fixed all of my issues. You can read more about their esbuild thing here:
https://www.netlify.com/blog/2021/04/02/modern-faster-netlify-functions/

Hope this helps!

@benmccann
Copy link
Member

The Netlify adapter has changed a lot since this issue was originally opened. There are several comments on this thread, but no clear way to reproduce the issue. As a result, I'm going to go ahead and close this. If you're still having problem, please file a new issue and provide a GitHub repository of a failing project and I'll take a look.

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

10 participants