tsx: Latest version of `tsx` causes `TypeError` `not a function`

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://github.com/SynthLuvr/tsx-bug

Problem & expected behavior (under 200 words)

To reproduce:

➜ git clone git@github.com:SynthLuvr/tsx-bug.git
➜ pnpm install
➜ pnpm tsx bug.ts
tsx-bug/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_memoizeCapped.js:15
  var result = memoize(func, function(key) {
               ^

TypeError: memoize is not a function

The culprit appears to be calling generateSeedPhrase() from @lucid-evolution/lucid before calling mnemonicToEntropy from bip39. For example, this works:

➜ pnpm tsx works.ts
e06ed2f736818e37420392a84251b4e996caa7b1348a02a06250bea9fff30a9f

Downgrading tsx to 4.19.4 works:

➜ pnpm install tsx@4.19.4
➜ pnpm tsx bug.ts
e70f70afef0ac3842ee84350a23216cd1e13474ca2ccfba3ad4162a6034f705a

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 proj

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

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 23
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Sorry for the disruption everyone! This release took a lot of work and was thoroughly tested before release but looks like it wasn’t enough.

Thanks to everyone that provided a reproduction—now we’ll have them as tests to ensure they pass before the next release.

I reverted the problematic changes for now: https://github.com/privatenumber/tsx/releases/tag/v4.20.3

I’ll keep investigating the root cause and aim to release a version that works across all Node versions soon.

/Users/lord/MyDir/node_modules/@opentelemetry/instrumentation-http/src/http.ts:97
export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentationConfig> {
                                         ^


TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (/Users/lord/MyDir/node_modules/@opentelemetry/instrumentation-http/src/http.ts:97:42)
    at loadCJSModule (node:internal/modules/esm/translators:161:3)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:196:7)
    at ModuleJob.runSync (node:internal/modules/esm/module_job:258:17)
    at require (node:internal/modules/esm/translators:146:9)
    at Object.<anonymous> (/Users/lord/MyDir/node_modules/@opentelemetry/instrumentation-http/src/index.ts:17:1)
    at loadCJSModule (node:internal/modules/esm/translators:161:3)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:196:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)

Node.js v22.13.1

Seems that since v4.20.2 I also get errors caused by wrong imports. Related to module resolution.

The commit that caused the issue seems to be c1882680bce9df3052bef23dbed1b95728e802bb and the file with the issue is src/esm/hook/load.ts

Without changing any code and everything working with version 4.20.1 updating to 4.20.2 I get this error using the import_client_dynamodb.GetItemCommand is not a constructor when using @aws-sdk/client-dynamodb

Feels related to this error.

If you are in the same case as me with shebang on a script to create a binary with npx or are using npx, I tried to add the previous version to the command to lock de version and it seems to work fine: #!/usr/bin/env -S npx --yes tsx@4.20.1 it is not a final solution but it might keep you safe from unexpected problems from unstable versions.

In my case the TypeError is with @kwsites/file-exists module (dependency of simple-git). However if I remove the module it keeps failing with other modules. It seems to be something wrong with export resolutions and commonjs as default is the keyword for exports in esm.