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

__exportStar in tsc output not transpiled to esm #389

Closed
nayeemrmn opened this issue Aug 4, 2022 · 2 comments
Closed

__exportStar in tsc output not transpiled to esm #389

nayeemrmn opened this issue Aug 4, 2022 · 2 comments

Comments

@nayeemrmn
Copy link

nayeemrmn commented Aug 4, 2022

If a node typescript library has the following content:

export const foo = 1;
export * from './bar'

and the author transpiles it using tsc targeting cjs, they get something resembling:

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "foo", { value: 1 });
__exportStar(require("./bar"), exports);

and they upload that to npm.

Understandably, esm.sh will recognise and generate an esm export for the Object.defineProperty(exports, "foo", { value: 1 }) but not the __exportStar((require("./bar"), exports). Despite the non-exactness I think it could be worth transpiling all instances of

__exportStar(require("<specifier>"), exports);

to

export * from "<specifier>";

As described above, this will enable a lot more modules from the Node/TS ecosystem to run correctly in browsers and Deno @ije.

Reproduction / example library (from @sinclairzx81)

As a result, import { Value } from "https://esm.sh/@sinclair/typebox@0.24.27/value" gives the following runtime error in Deno:

error: Uncaught SyntaxError: The requested module 'https://esm.sh/@sinclair/typebox@0.24.27/value' does not provide an export named 'Value'
import { Value } from "https://esm.sh/@sinclair/typebox@0.24.27/value";
         ^
@ije
Copy link
Member

ije commented Aug 4, 2022

i added tslib.__exportStar support in https://github.com/ije/esm.sh/blob/b81ea0f66c41a61f6db8666de3748ea0c629919f/packages/esm-cjs-lexer/src/test.rs#L597, but didn't consider the bundled __exportStar

@ije ije closed this as completed in 007ac43 Aug 5, 2022
@nayeemrmn
Copy link
Author

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

2 participants