Skip to content

[Bug] ERR_REQUIRE_ESM when using @stackframe/js in CommonJS/TypeScript Nest Js project #662

@GathsaraH

Description

@GathsaraH

Description:
When attempting to use @stackframe/js@2.8.11 in a project compiled with SWC and using TypeScript, the following error occurs at runtime due to an improper import of an ESM module via require():

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/@stackframe/stack-shared/dist/esm/utils/compile-time.js from .../node_modules/@stackframe/js/dist/lib/stack-app/apps/implementations/index.js not supported.
Instead change the require of compile-time.js in .../index.js to a dynamic import() which is available in all CommonJS modules.

Reproduction Steps:

Create a Nest Js TypeScript project using CommonJS or SWC for transpilation.

Install @stackframe/js@2.8.11 and attempt to use it (e.g., import in onModuleInit() or a dynamic runtime context).

Run the project.

Observe the ESM import error from the compiled @stackframe/js package.

@stackframe/js is trying to require() an ESM file from @stackframe/stack-shared:
var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-time");

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions