Skip to content

Netlify JS OpenAPI throws: "The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined" #5591

Open
@major-mayer

Description

@major-mayer

Describe the bug

I've set up a fairly simple hook to delete form submissions after they have been forwarded via mail (based on this guide).

import { NetlifyAPI } from 'netlify'

exports.handler = async function () {
  const client = new NetlifyAPI(process.env.NETLIFY_API_ACCESS_TOKEN)

  const submissions = await client
    .listSiteSubmissions({
      site_id: process.env.SITE_ID,
    })
    .catch((e) => console.log('Error getting submissions', e))

  if (submissions.length) {
    for (i = 0; i < submissions.length; i++) {
      await client.deleteSubmission({ submission_id: submissions[i].id })
    }
    return {
      statusCode: 200,
      body: 'Submissions deleted',
    }
  } else {
    return {
      statusCode: 200,
      body: 'No submissions to delete',
    }
  }
}

It was working well for the last years, but now I noticed that the submissions are not deleted anymore.
I found the following error message in the function logs:

Apr 15, 12:04:25 PM: INIT_START Runtime Version: nodejs:18.v26	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:0cdcfbdefbc5e7d3343f73c2e2dd3cba17d61dea0686b404502a0c9ce83931b9
Apr 15, 12:04:25 PM: 2024-04-15T10:04:25.901Z	undefined	ERROR	Uncaught Exception 	{"errorType":"TypeError","errorMessage":"The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined","code":"ERR_INVALID_ARG_VALUE","stack":["TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined","    at new NodeError (node:internal/errors:405:5)","    at createRequire (node:internal/modules/cjs/loader:1497:11)","    at Object.<anonymous> (/var/task/functions/submission-created.js:8886:48)","    at Module._compile (node:internal/modules/cjs/loader:1356:14)","    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)","    at Module.load (node:internal/modules/cjs/loader:1197:32)","    at Module._load (node:internal/modules/cjs/loader:1013:12)","    at Module.require (node:internal/modules/cjs/loader:1225:19)","    at require (node:internal/modules/helpers:177:18)","    at Object.<anonymous> (/var/task/submission-created.js:1:18)"]}
Apr 15, 12:04:25 PM: INIT_REPORT Init Duration: 237.14 ms	Phase: init	Status: error	Error Type: Runtime.ExitError
Apr 15, 12:04:26 PM: 2024-04-15T10:04:26.222Z	undefined	ERROR	Uncaught Exception 	{"errorType":"TypeError","errorMessage":"The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined","code":"ERR_INVALID_ARG_VALUE","stack":["TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined","    at new NodeError (node:internal/errors:405:5)","    at createRequire (node:internal/modules/cjs/loader:1497:11)","    at Object.<anonymous> (/var/task/functions/submission-created.js:8886:48)","    at Module._compile (node:internal/modules/cjs/loader:1356:14)","    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)","    at Module.load (node:internal/modules/cjs/loader:1197:32)","    at Module._load (node:internal/modules/cjs/loader:1013:12)","    at Module.require (node:internal/modules/cjs/loader:1225:19)","    at require (node:internal/modules/helpers:177:18)","    at Object.<anonymous> (/var/task/submission-created.js:1:18)"]}
Apr 15, 12:04:26 PM: INIT_REPORT Init Duration: 287.29 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
Apr 15, 12:04:26 PM: Unknown application error occurred
Runtime.Unknown
Apr 15, 12:04:26 PM: a18ab59c Duration: 287.97 ms	Memory Usage: 21 MB	

It seems like the import is somehow broken, probably because this createRequire() call fails.

I was also able to reproduce this problem locally when I executed the function manually using npx netlify functions:invoke submission-created.
The messages still goes through tho, it's just the cleanup hook that fails.

This issue was reported twice already, one time in the old repo and the new monorepo, but both are stale/ closed.
Maybe this time we can finally get a resolution.

I am on the latest version "13.1.14" of the Netlify package.

Steps to reproduce

  1. Add the snippet from above to the file functions/submission-created.js
  2. Either deploy the repo to Netlify or start the Dev server
  3. Submit a form or execute the function manually using npx netlify functions:invoke submission-created

Configuration

[build]
publish = "public"
command = "tinacms build && hugo --gc --minify"
functions = "functions"

[context.production.environment]
HUGO_VERSION = "0.119.0"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"

[[redirects]]
    from = '/api/*'
    to = '/.netlify/functions/api/:splat'
    status = 200

[functions]
    # From here: https://answers.netlify.com/t/cloudinary-netlify-functions-enoent-bridge-js/95918/4
    external_node_modules = ["express", "vm2"]
    node_bundler = 'esbuild'

# Use [dev] to set configuration overrides for local development environments run using Netlify Dev 
[dev]
publish = "public"
command = "npm run dev"
functions = "functions"
targetPort = 1313

Deploy logs

The issue doesn't occur while deploying, but during runtime.
For runtime function logs, see above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staletype: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions