TypeError thrown on Netlify JS client instantiation, on local dev server
mosesoak opened this issue · 0 comments
- Do you want to request a feature or report a bug?
Bug
- What is the current behavior?
When invoking a function locally using netlify functions:invoke
, a type error is thrown when instantiating this client using new NetlifyAPI(token)
- If the current behavior is a bug, please provide the steps to reproduce.
Create and invoke a simple test function, in which the client is instantiated using a valid token:
import { Handler } from '@netlify/functions';
import { NetlifyAPI } from 'netlify';
const { NETLIFY_TOKEN } = process.env;
export const handler: Handler = async (event) => {
if (!NETLIFY_TOKEN) {
return { statusCode: 500, body: 'missing token' };
}
const netlifyClient = new NetlifyAPI(NETLIFY_TOKEN);
return { statusCode: 200 };
};
The server throws an error:
Request from ::ffff:127.0.0.1: POST /.netlify/functions/error-test
{"level":"error","message":"End - Error:"}
{"errorMessage":"The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined","errorType":"TypeError","level":"error","stackTrace":["createRequire (internal/modules/cjs/loader.js:1186:11)","Object.<anonymous> (myproject/node_modules/netlify/src/open_api.js:5:17)","Module._compile (internal/modules/cjs/loader.js:1085:14)","Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)","Module.load (internal/modules/cjs/loader.js:950:32)","Function.Module._load (internal/modules/cjs/loader.js:790:14)","Module.require (internal/modules/cjs/loader.js:974:19)","require (internal/modules/cjs/helpers.js:92:18)","Object.<anonymous> (myproject/.netlify/functions-serve/error-test/error-test.js:1:18)","Module._compile (internal/modules/cjs/loader.js:1085:14)"]}
With the invoke call stack trace:
TypeError: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
createRequire (internal/modules/cjs/loader.js:1186:11)
Object.<anonymous> (myproject/node_modules/netlify/src/open_api.js:5:17)
Module._compile (internal/modules/cjs/loader.js:1085:14)
Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
Module.load (internal/modules/cjs/loader.js:950:32)
Function.Module._load (internal/modules/cjs/loader.js:790:14)
Module.require (internal/modules/cjs/loader.js:974:19)
require (internal/modules/cjs/helpers.js:92:18)
Object.<anonymous> (myproject/.netlify/functions-serve/error-test/error-test.js:1:18)
Module._compile (internal/modules/cjs/loader.js:1085:14)
- What is the expected behavior?
It doesn't blow up when you instantiate it.
I'd like to be able to use this client for the sake of convenience, but will revert to using standard fetch
with a few headers to access the Netlify API since this doesn't seem usable at all.
- Please mention your node.js, and operating system version.
Using:
"netlify": "^11.0.1",
"@netlify/functions": "^1.0.0",
"netlify-cli": "^9.16.6",
Node v14.17.1
Windows 10 + WSL2