NetlifyAPI: TypeError: The argument 'filename' must be a file URL object

In attempting to create a function that uses the Netlify API I have this:

import { NetlifyAPI } from "netlify"
const client = new NetlifyAPI(process.env.NETLIFY_API_KEY)

const handler = async function(event, context) {

   * Trigger a rebuild using the API
  const response = await client.createSiteBuild({ site_id: process.env.SITE_ID })

  return {
    statusCode: 200,

module.exports.handler = handler;

Regardless of trying to run this locally, or when deployed, I receive the error

TypeError: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined

This happens with the import (I tested removing the const client and const response lines and the same error was still thrown.) Looking at this thread it would appear use of NetlifyAPI in a function is possible (I’ve tried require('netlify') with the same result.

If I create a script.js with similar code and run node script.js everything works fine. Am I missing something—is using NetlifyAPI like this not possible? Am I doing something not quite right—is the implementation in a function different than a script?

Package is netlify@11.0.0. The idea behind this is to use it as a scheduled function to trigger a rebuild periodically. Is there a better way to do this?

Hey @coelmay,

While this gets investigated, I think you can use node fetch or Axios to accomplish the same task. You simply need to make a call to that API endpoint with the auth token as the authorization header in bearer token.

Chances are our Function bundling is having issues at the moment, so maybe you’d have a hard luck with Node Fetch and Axios too. I’d suggest keeping an eye on: Working on netlify dev, not on actual deploy · Issue #1036 · netlify/zip-it-and-ship-it · GitHub if you have issues.

1 Like

Thanks @hrishikesh.

Using Fetch worked locally when I tested locally. Waiting for the scheduled function to trigger so my fingers are currently crossed :slight_smile: