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

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

Open
benasher44 opened this issue May 8, 2024 · 0 comments
Open

Comments

@benasher44
Copy link

benasher44 commented May 8, 2024

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
@benasher44 benasher44 changed the title Generated JS code doesn't work with cjs-module-lexer Generated JS code doesn't work with node ESM due to cjs-module-lexer May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant