Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Instantiation of Netlify API client breaks Netlify TS functions #989

Open
mfanuzzi opened this issue Jan 31, 2022 · 1 comment
Open

Instantiation of Netlify API client breaks Netlify TS functions #989

mfanuzzi opened this issue Jan 31, 2022 · 1 comment

Comments

@mfanuzzi
Copy link

- Do you want to request a feature or report a bug?
a bug

- What is the current behavior?
importing this library into a Netlify typescript function causes a fatal runtime error

- If the current behavior is a bug, please provide the steps to reproduce.

Create a file called hello.ts in your functions folder:

import { Handler } from '@netlify/functions';
import { NetlifyAPI } from 'netlify';

const handler: Handler = async (event, context) => {
  const client = new NetlifyAPI('test') as any; // <-- this is the line that breaks it

  return {
    statusCode: 200,
    body: JSON.stringify({ message: 'Hello World' }),
  };
};

export { handler };

Then run netlify dev and visit that endpoint; you'll get a 500:

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> (/home/mfan/projects/acb001-crm/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> (/home/mfan/projects/acb001-crm/.netlify/functions-serve/hello/hello.js:1:18)
  Module._compile (internal/modules/cjs/loader.js:1085:14)

- What is the expected behavior?
The client instantiates

- Please mention your node.js, and operating system version.
Node 14, with:

    "netlify": "^10.1.2",
    "@netlify/functions": "^0.11.0",
    "netlify-cli": "^8.15.1",
@ehmicky
Copy link
Contributor

ehmicky commented Feb 1, 2022

Hi @mfanuzzi,

It seems like import.meta.url in this line of code is undefined.

This seems this bug might not be due to js-client, but to the bundling process done on TypeScript Functions, so I am transferring this to the repository related to it.

cc @eduardoboucas @netlify-team-account-1

@ehmicky ehmicky transferred this issue from netlify/js-client Feb 1, 2022
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

2 participants