tsx icon indicating copy to clipboard operation
tsx copied to clipboard

[yarn] `[ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected array buffer, or typed array to be returned for the "source" from the "transformSource" function but got undefined.`

Open loynoir opened this issue 1 year ago • 7 comments

Problem

yarn tsx ./src/reproduce.ts throw error

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected array buffer, or typed array to be returned for the "source" from the "transformSource" function but got undefined.
    at __node_internal_captureLargerStackTrace (node:internal/errors:497:5)
    at new NodeError (node:internal/errors:406:5)
    at assertBufferSource (node:internal/modules/esm/translators:84:9)
    at stringify (node:internal/modules/esm/translators:94:3)
    at createCJSModuleWrap (node:internal/modules/esm/translators:219:12)
    at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:297:10) {
  code: 'ERR_INVALID_RETURN_PROPERTY_VALUE'
}

Node.js v20.8.0

Expected behavior

No error.

Minimal reproduction URL

https://github.com/loynoir/reproduce-tsx-338

Version

3.13.0

Node.js version

v20.8.0

Package manager

yarn

Operating system

Linux

Contributions

  • [ ] I plan to open a pull request for this issue
  • [ ] I plan to make a financial contribution to this project

loynoir avatar Oct 16 '23 04:10 loynoir

Would you try with node 19? If you're using yarn PnP, the version should be 19.6.0 and up.

SnowMarble avatar Oct 17 '23 04:10 SnowMarble

Would you try with node 19? If you're using yarn PnP, the version should be 19.6.0 and up.

works with nodejs 19.

Is there possibility tsx will work with Yarn PnP and node 20+ in the future?

idchlife avatar Oct 18 '23 13:10 idchlife

Latest working version for me is v20.5.1

MarZab avatar Oct 26 '23 21:10 MarZab

Not working with Node v20.9.0 but does work in v19.9.0

robinelvin avatar Nov 07 '23 11:11 robinelvin

Personally, I dont use yarn so this wont be a priority for me to work on.

If its a priority for you, feel free to submit a PR with tests and Id be happy to review.

privatenumber avatar Nov 07 '23 11:11 privatenumber

FYI, yarn combine with a very simple loader would work.

https://github.com/esbuild-kit/esm-loader/issues/81

      const source2 = esbuild_transform_fallback_to_ts_transpile(...transpileOptions)

      try {
        await nextLoad(url, context)
        return { format, responseURL: url, source: source2 }
      } catch {
        return { format, responseURL: url, source: source2, shortCircuit: true }
      }

loynoir avatar Nov 07 '23 15:11 loynoir

Possible upstream fix https://github.com/nodejs/node/issues/50435

MarZab avatar Nov 29 '23 09:11 MarZab