Skip to content

Generated JS code doesn't work with node ESM due to cjs-module-lexer #576

Open
@benasher44

Description

@benasher44

Issue Summary

Using a named import like import { Twilio } from "twilio"; fails on node in ESM mode because node uses cjs-module-lexer to statistically analyze imports. Twilio's OpenAI generator generates code that cjs-module-lexer can't lex to determine the named exports.

Steps to Reproduce

  1. Create test.mjs (forces node to treat as ESM).
  2. Add import { Twilio } from "twilio";
  3. Run node test.mjs

Code Snippet

import { Twilio } from "twilio";

Exception/Log

import { Twilio } from "twilio";
         ^^^^^^
SyntaxError: Named export 'Twilio' not found. The requested module 'twilio' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

Technical details:

  • twilio-node version: 5.0.0
  • node version: 20.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions