cevek / ttypescript

Over TypeScript tool to use custom transformers in the tsconfig.json
1.53k stars 56 forks source link

Cannot set property constructor of [object Object] which has only a getter #150

Closed jimmywarting closed 1 year ago

jimmywarting commented 1 year ago

This is an error i get when i'm trying to install a package and building it.

/node_modules/ttypescript/lib/loadTypescript.js:13
        function __() { this.constructor = d; }
                                         ^

TypeError: Cannot set property constructor of [object Object] which has only a getter
    at new __ (/node_modules/ttypescript/lib/loadTypescript.js:13:42)
    at __extends (/node_modules/ttypescript/lib/loadTypescript.js:14:84)
    at /node_modules/ttypescript/lib/loadTypescript.js:65:5
    at Object.<anonymous> (/node_modules/ttypescript/lib/loadTypescript.js:100:2)

It looks like you are compiling to really old javascript es5 syntax and using lib es2015 it's hard to debug the compiled source.

can i ask that you please compile typescript to a newer-ish version?

fyi, i'm using NodeJS v18.17.1 and ttypescript v1.5.12

jimmywarting commented 1 year ago

think it got fixed by upgrading ttypescript version to v1.5.15

danielsitnik commented 1 year ago

Strangely enough, I have this error with ttypescript 1.5.13 when running jest tests, but only on Linux machines. 😦 It started happening on our CI machine yesterday, but it works perfectly fine on my macOS.

These machines run Ubuntu Linux, node 16.20.2. The source code uses TypeScript 4.9.3.

We have been using these exact same versions for more than 7 months with no problem.

I updated to 1.5.15 and the problem went away, but I'm still curious.

@jimmywarting please can you help me understand why this problem happens in the first place?

ts-jest[Importer] (ERROR) failed loading module 'ttypescript' Cannot set property constructor of [object Object] which has only a getter
 FAIL  src/test/application/service/RoutingService.test.ts
  ● Test suite failed to run

    Loading module ttypescript failed with error: Cannot set property constructor of [object Object] which has only a getter

      at Importer._import (node_modules/ts-jest/dist/utils/importer.js:139:19)
      at Importer.typescript (node_modules/ts-jest/dist/utils/importer.js:80:21)
      at new ConfigSet (node_modules/ts-jest/dist/legacy/config/config-set.js:178:51)
      at TsJestTransformer._createConfigSet (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:150:16)
      at TsJestTransformer._configsFor (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:129:34)
      at TsJestTransformer.getCacheKey (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:265:28)
      at ScriptTransformer._getCacheKey (node_modules/@jest/transform/build/ScriptTransformer.js:278:41)
      at ScriptTransformer._getFileCachePath (node_modules/@jest/transform/build/ScriptTransformer.js:349:27)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:595:32)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:765:40)
jimmywarting commented 1 year ago

Could have been that it have worked on a earlier NodeJS version, and upgrading the nodejs version could have broken it.

danielsitnik commented 1 year ago

You're right. I was using 16.20.1 locally and the CI machine was on 16.20.2.

Anyway, still wondering why a simple patch version caused this.

jimmywarting commented 1 year ago

lol, was it only a minor patch (bug fix) from NodeJS version x.x.1 -> x.x.2 that cause this? should have been a major breaking change from NodeJS side. 🤪

can not put the blame on ttypescript really... should blame NodeJS then.


i only notice this NodeJS version problem and reported this issue cuz i was using a NodeJS v18+ locally while the other developer and docker container used v14 or early v16.

Makes me wonder how many packages that utilize typescript have been broken for using typescripts bundler that generated old-ish "bad" code.

cuz this function __() { this.constructor = d; } dose not come from ttypescript itself... that is the result of a bundler that compiles to a older more "compatible" version for older platforms.

Emt-lin commented 1 year ago

Envirment: node v18.17.1、TypeScript 4.9.3、ttypescript v1.5.13

In my M1 mac machine, alreay have this error. (update v1.5.15, this problem was resolved) But in my another intel mac machine, nothing error. So, I'm also curious.

jimmywarting commented 1 year ago

Do you use the exact same node version and typescript version on both?

Emt-lin commented 1 year ago

@jimmywarting yes, I'm sure.