Skip to content

Does not handle import * of current file #82

Description

@timfish

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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