privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
8.61k stars 132 forks source link

[Regression] SyntaxError when calling `require()` on a JSON file since 4.13.0 #587

Closed geotry closed 2 weeks ago

geotry commented 2 weeks ago

Acknowledgements

Minimal reproduction URL

See below

Problem & expected behavior (under 200 words)

Calling tsx.require() on a JSON file from module "tsx/cjs/api" throws a SyntaxError since 4.13.0, and worked in previous version 4.12.1 (https://github.com/privatenumber/tsx/compare/v4.12.1...v4.13.0)

Reproduction steps

Tested on node v20.12.2

Outputs the JSON object

npm i tsx@4.12.1
node -e 'console.log(require("tsx/cjs/api").require("./package.json", "."))'

Throws a SyntaxError

npm i tsx@4.13.0
node -e 'console.log(require("tsx/cjs/api").require("./package.json", "."))'

***/package.json:2
  "name": "***",
        ^

SyntaxError: Unexpected token ':'
    at internalCompileFunction (node:internal/vm:128:18)
    at wrapSafe (node:internal/modules/cjs/loader:1280:20)
    at Module._compile (node:internal/modules/cjs/loader:1332:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Object.transformer [as .js] (***/node_modules/tsx/dist/register-BPRJR7M6.cjs:2:589)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at Object.require (node:internal/modules/helpers:179:18)
    at Function.scopedRequire [as require] (***/node_modules/tsx/dist/register-BPRJR7M6.cjs:2:1770)

Bugs are expected to be fixed by those affected by it

Compensating engineering work financially will speed up resolution

privatenumber commented 2 weeks ago

:tada: This issue has been resolved in v4.15.3

If you rely on this project, please consider making a donation :heart: :pray: