Local Netlify Plugin fails: Error: function () { [native code] } could not be cloned

Hello!

I created a local netlify plugin at tools/netlify-plugin-percy-test/index.js:

const { Octokit } = require("@octokit/core");

module.exports = {
  async onSuccess({ netlifyConfig, inputs }) {
    const {
      COMMIT_REF: ref,
      DEPLOY_PRIME_URL: origin,
      GITHUB_PAT: auth,
    } = netlifyConfig.build.environment ?? {}

    const { owner, repository, workflowId } = inputs;

    const octokit = new Octokit({ auth });

    console.log({ owner, repository, origin, ref, workflowId });

    await octokit.request('POST /repos/{owner}/{repository}/actions/workflows/{workflowId}/dispatches', {
      owner,
      ref,
      repository,
      workflowId,
      inputs: {
        origin,
      }
    });
  },
}

with this manifest.yml

name: netlify-plugin-percy-test
inputs:
  - name: owner
    description: Github repository owner (scope). e.g. for `https://github.com/actions/netlify`, the `owner` is `"actions"`
  - name: repository
    description: Github repository name. e.g. for `https://github.com/actions/netlify`, the `repository` is `"netlify"`
  - name: workflowId
    description: Name of the workflow file e.g. `"visual-regression.yml"` or the workflow id number e.g. `42`

and this netlify.toml

[build]
  command = "npm run build"

[[redirects]]
  from = "/demo/*"
  to = "/demo/index.html"
  status = 200

[[plugins]]
  package = "/tools/netlify-plugin-percy-test"

  [plugins.inputs]
    owner = "patternfly"
    repository = "patternfly-elements"
    workflowId = "visual-regression.yml"

And the result of running my build was the following:

2:20:29 PM: ────────────────────────────────────────────────────────────────
2:20:29 PM:   Plugin "/tools/netlify-plugin-percy-test" internal error      
2:20:29 PM: ────────────────────────────────────────────────────────────────
2:20:29 PM: ​
2:20:29 PM:   Error message
2:20:29 PM:   Error: function () { [native code] } could not be cloned.
2:20:29 PM: ​
2:20:29 PM:   Plugin details
2:20:29 PM:   Package:        /tools/netlify-plugin-percy-test
2:20:29 PM:   Version:        0.0.1
2:20:29 PM: ​
2:20:29 PM:   Error location
2:20:29 PM:   In "onSuccess" event in "/tools/netlify-plugin-percy-test" from netlify.toml
2:20:29 PM:       at writeChannelMessage (node:internal/child_process/serialization:82:9)
2:20:29 PM:       at process.target._send (node:internal/child_process:819:17)
2:20:29 PM:       at process.target.send (node:internal/child_process:719:19)
2:20:29 PM:       at node:internal/util:360:7
2:20:29 PM:       at new Promise (<anonymous>)
2:20:29 PM:       at bound  (node:internal/util:346:12)
2:20:29 PM:       at sendEventToParent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/ipc.js:123:46)
2:20:29 PM:       at handleError (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/child/error.js:13:9)
2:20:29 PM:       at handleEvent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/child/main.js:45:11)
2:20:29 PM:       at processTicksAndRejections (node:internal/process/task_queues:96:5)
2:20:29 PM: ​
2:20:29 PM:   Resolved config
2:20:29 PM:   build:
2:20:29 PM:     command: npm run build
2:20:29 PM:     commandOrigin: config
2:20:29 PM:     environment:
2:20:29 PM:       - ELEVENTY_ENV
2:20:29 PM:       - GITHUB_PAT
2:20:29 PM:       - NODE_VERSION
2:20:29 PM:       - REVIEW_ID
2:20:29 PM:     publish: /opt/build/repo/_site
2:20:29 PM:     publishOrigin: ui
2:20:29 PM:   plugins:
2:20:29 PM:     - inputs: {}
2:20:29 PM:       origin: ui
2:20:29 PM:       package: '@netlify/plugin-lighthouse'
2:20:29 PM:     - inputs: {}
2:20:29 PM:       origin: config
2:20:29 PM:       package: /tools/netlify-plugin-percy-test
2:20:29 PM:   redirects:
2:20:29 PM:     - from: /demo/*
      status: 200
      to: /demo/index.html
  redirectsOrigin: config
​

I’m not really sure what’s going on here. Perhaps it’s the console.log call, or something internal to octokit?

Any advice is welcome

1 Like

Hey @bennypowers,

Could you share a repo for us to reproduce this issue?

@hrishikesh We are also seeing this issue for some users of our plugin. We haven’t been able to get a consistent failure, but a user shared a build log here: Plugin "@quarto/netlify-plugin-quarto" internal error Β· Issue #1956 Β· quarto-dev/quarto-cli Β· GitHub

We saw this issue in onPreBuild event instead of β€œonSuccess”, though:

2:59:45 PM:   Error location
2:59:45 PM:   In "onPreBuild" event in "@quarto/netlify-plugin-quarto" from netlify.toml and package.json
2:59:45 PM:       at writeChannelMessage (node:internal/child_process/serialization:109:9)
2:59:45 PM:       at process.target._send (node:internal/child_process:840:17)
2:59:45 PM:       at process.target.send (node:internal/child_process:740:19)
2:59:45 PM:       at node:internal/util:361:7
2:59:45 PM:       at new Promise (<anonymous>)
2:59:45 PM:       at bound  (node:internal/util:347:12)
2:59:45 PM:       at sendEventToParent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/ipc.js:123:46)
2:59:45 PM:       at handleError (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/child/error.js:13:9)
2:59:45 PM:       at handleEvent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/child/main.js:45:11)
2:59:45 PM:       at processTicksAndRejections (node:internal/process/task_queues:96:5)

If it helps, the build and deploy ids are:

2:59:44 PM:   buildId: 62fd64c32597ef0008438c7e
2:59:44 PM:   deployId: 62fd64c32597ef0008438c80

Hey @Carlos_Scheidegger,

This is interesting. We’ve seen this error in the past, but that’s only on Node 18. Turns out there is some issue that we need to fix for this to work with Node 18. However, I can see that this build was using Node 16. So not sure what could cause this. We’ve escalated it to the devs.

Meanwhile, is it possible to try to share the deploy ID of the deploy that triggers this error - but this time, make sure NETLIFY_BUILD_DEBUG variable is set to true?

@hrishikesh Sorry for the delayed answer. The client who originally reported this to me never came back, but now we have an internal person at RStudio who has been seeing the same issue, and I can work with him directly. Here’s a failed build: Custom cmd in the Netlify config by sellorm Β· Pull Request #1 Β· sellorm/qweb Β· GitHub

The full log is here: Netlify App

I’m going to ask him to update the build with NETLIFY_BUILD_DEBUG=true as well.

Hi @Carlos_Scheidegger,

Thanks for the follow-up.

Reviewing the build, it seems to be breaking on the onPreBuild block. Would it be possible to include additional logging into the function onPreBuild? We’re hoping it will allow us to see what is causing the issue.

Here’s a run with NETLIFY_BUILD_DEBUG=true:

@Melvin , I should be able to do it, if you tell me more specifically what additional information you want me to log. Thank yoU!

Hey @Carlos_Scheidegger,

Thanks for the debug info - I think that already prints some useful info Netlify App

It appears to me that something is going wrong with the API calls. Could you check that?

Additionally, what Melvin was trying to say is that, you could add some console.log() after each step so that you (and we) can see where exactly it’s failing.