Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

TypeError thrown on Netlify JS client instantiation, on local dev server #700

Open
mosesoak opened this issue Apr 11, 2022 · 0 comments
Open

Comments

@mosesoak
Copy link

- 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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant