Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot instantiate Netlify client in JavaScript with Bun #5613

Open
pachico opened this issue Apr 29, 2024 · 1 comment
Open

Cannot instantiate Netlify client in JavaScript with Bun #5613

pachico opened this issue Apr 29, 2024 · 1 comment
Labels
type: bug code to address defects in shipped code

Comments

@pachico
Copy link

pachico commented Apr 29, 2024

Describe the bug

When I try to create a client with these lines:

// file foo.ts
import { NetlifyAPI } from 'netlify';

try {
    const client = new NetlifyAPI("my-token");
    console.log('Client created successfully');
} catch (error) {
    console.error('Error creating Netlify client:', error);
}

I get the following error

bun run foo.ts 
1 | import omit from 'omit.js';
2 | import { openApiSpec } from './open_api.js';
3 | // Retrieve all OpenAPI operations
4 | export const getOperations = function () {
5 |     return Object.entries(openApiSpec.paths).flatMap(([path, pathItem]) => {
6 |         const operations = omit.default(pathItem, ['parameters']);
                               ^
TypeError: omit.default is not a function. (In 'omit.default(pathItem, ["parameters"])', 'omit.default' is undefined)
      at /[redacted]/node_modules/netlify/lib/operations.js:6:28
      at /[redacted]/node_modules/netlify/lib/index.js:87:24

Steps to reproduce

  1. Create new file foo.ts
  2. Add dependency via bun with bun add netlify
  3. paste content provided above in the file
  4. execute with bun run foo.ts

Configuration

Deploy logs

@pachico pachico added the type: bug code to address defects in shipped code label Apr 29, 2024
@Jarred-Sumner
Copy link

@pachico if this works in Node, then it's a bug in Bun and not in Netlify.

Without reading omit.js's code, my guess is Bun is respecting __esModule on omit.js when converting to ESM, so omit.default is undefined since that's the equivalent of require("omit.js").default.default and that would cause the error "omit.default" is not a function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants