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

Does not handle import * of current file #82

Closed
timfish opened this issue May 27, 2024 · 0 comments · Fixed by #83
Closed

Does not handle import * of current file #82

timfish opened this issue May 27, 2024 · 0 comments · Fixed by #83

Comments

@timfish
Copy link
Contributor

timfish commented May 27, 2024

Another strange ESM edge case!

Some files in the openapi sdk import * themselves like below.

I don't know how common this is elsewhere but these files are auto-generated which might explain this strange pattern.

batches.mjs

// File generated from our OpenAPI spec by Stainless.
import * as BatchesAPI from "./batches.mjs";
export class Batches {}
export class BatchesPage {}
(function (Batches) {
    Batches.BatchesPage = BatchesAPI.BatchesPage;
})(Batches || (Batches = {}));

If you import the above in Node, there is no error.

If the import-in-the-middle/hook.mjs is registered, you get the following error:

file:///Users/tim/Documents/Repositories/repro/more.mjs:5
    Batches.BatchesPage = BatchesAPI.BatchesPage;
                                     ^
ReferenceError: Cannot access 'BatchesPage' before initialization
    at file:///Users/tim/Documents/Repositories/repro/more.mjs:5:38
    at file:///Users/tim/Documents/Repositories/repro/more.mjs:6:3
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:475:24)
    at async file:///Users/tim/Documents/Repositories/repro/test.mjs:5:1
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

Successfully merging a pull request may close this issue.

1 participant