Skip to content

import.meta is left unshimmed by the CJS transform when comments or newlines split the tokens #828

Closed

Description

@AtofStryker

Acknowledgements

  • I read the documentation and searched existing issues to avoid duplicates
  • I understand this is a bug tracker and anything other than a proven bug will be closed
  • I understand this is a free project and relies on community contributions
  • I read and understood the Contribution guide

Minimal reproduction URL

https://stackblitz.com/edit/tsx-reproduction?file=package.json,entry.cjs,deps.js

Problem & expected behavior (under 200 words)

Requiring an ESM file through the CJS hook crashes when a comment or newline sits between the import and .meta tokens:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object,
file URL string, or absolute path string. Received undefined
    at createRequire (node:internal/modules/cjs/loader:2025:11)

The failing form is createRequire(import /*::(_)*/.meta.url) — valid syntax, and plain node entry.cjs (native require(esm), Node 20.19+) loads it fine. Under tsx, import.meta lowers to an empty object and .url is undefined.

Cause: transformSync in src/utils/transform/index.ts only passes the import.meta define to esbuild when code.includes('import.meta'). Comments or newlines between the tokens defeat the textual search. esbuild's define itself handles those forms correctly once configured.

This is hit in the wild: @babel/helper-define-polyfill-provider@1.x ships exactly that form (a preserved Flow type-comment — source at the 1.0.0 tag), so any CJS code that pulls in @babel/preset-env 8 under the hook crashes — e.g. @angular-devkit/build-angular 22.1, found via cypress-io/cypress#34461.

Reproduced on 4.22.4 through 4.23.8.

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Compensating engineering work will speed up resolution and support the project

  • I'm willing to offer $10 for financial support

Activity

  1. added
    bug
    on Aug 5, 2026
  2. privatenumber commented on Aug 10, 2026

    @privatenumber
    Owner

    This issue is now resolved in v4.23.12.

    If you're able to, your sponsorship would be very much appreciated.

  3. added a commit that references this issue on Aug 10, 2026
    ed9d330
  4. added a commit that references this issue on Aug 24, 2026
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

    bugpending triagereleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions