azu / commonjs-to-es-module-codemod

Codemod that convert CommonJS(require/exports) to ES Modules(import/export) for JavaScript/TypeScript
MIT License
80 stars 15 forks source link

Fix bug with named exports #12

Closed wesbos closed 1 year ago

wesbos commented 1 year ago

There is a bug where this code:

const products = require('./data/products');
exports.products = products;

causes this error:

Transformation error ("products" does not match field "name": Identifier | null of type ExportSpecifier)

This seems to fix it.

References:

  1. https://github.com/homer0/cjs2esm/pull/15/files
  2. https://github.com/benjamn/ast-types/issues/425#issuecomment-1007846129
wesbos commented 1 year ago

Fixed!

azu commented 1 year ago

https://github.com/azu/commonjs-to-es-module-codemod/releases/tag/v0.5.1

Thanks!

wesbos commented 1 year ago

Thank you for the quick release