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?