Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jimmywarting opened this issue Aug 24, 2023 · 8 comments

Comments

@jimmywarting
Copy link

jimmywarting commented Aug 24, 2023

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
Copy link
Author

jimmywarting commented Aug 24, 2023

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

@danielsitnik
Copy link

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
Copy link
Author

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

@danielsitnik
Copy link

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
Copy link
Author

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
Copy link

Emt-lin commented Sep 6, 2023

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
Copy link
Author

jimmywarting commented Sep 6, 2023

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

@Emt-lin
Copy link

Emt-lin commented Sep 8, 2023

@jimmywarting yes, I'm sure.

iknowhtml added a commit to ava-labs/avalanche-wallet-sdk that referenced this issue Nov 16, 2023
AndrewADev added a commit to AndrewADev/push-prebuilt-action that referenced this issue Feb 9, 2024
We were seeing an issue running the main workflow after the upgrade to Node v20.

The issue seems to match this one here: cevek/ttypescript#150
yokots added a commit to yokots/Hippy that referenced this issue Aug 1, 2024
Current ttypescript version not support node v16.20.2, the latest v16 version.
It will cause this issue: cevek/ttypescript#150
zealotchen0 added a commit to Tencent/Hippy that referenced this issue Sep 29, 2024
* chore(drive/js): bump up ttypescript version

Current ttypescript version not support node v16.20.2, the latest v16 version.
It will cause this issue: cevek/ttypescript#150

* fix(hipp-vue-next): correct patchProps types

align patchProps types with vue runtime core, but
there also have some spec tests to fix

* refactor(vue-next): minify generated style code

just like fromSsrAstNodes, optimize the output in hippy-vue-css-loader,
and make hippy-vue-next-style-parser to compatible with old and new format.

* build(example-scripts): remove webpack.NamedModulesPlugin

webpack.NamedModulesPlugin was deprecated in v4 and removed in v5.
these plugin are default in devlopment mode and should not be configured in production mode,
because it will expose file path and increase bundle sizes.

https://v4.webpack.js.org/migrate/4/#deprecatedremoved-plugins

* chore(examples): update vue3 assets

---------

Co-authored-by: zealotchen <92966734+zealotchen0@users.noreply.github.com>
zealotchen0 added a commit to Tencent/Hippy that referenced this issue Nov 5, 2024
* chore(drive/js): bump up ttypescript version

Current ttypescript version not support node v16.20.2, the latest v16 version.
It will cause this issue: cevek/ttypescript#150

* fix(hipp-vue-next): correct patchProps types

align patchProps types with vue runtime core, but
there also have some spec tests to fix

* refactor(vue-next): minify generated style code

just like fromSsrAstNodes, optimize the output in hippy-vue-css-loader,
and make hippy-vue-next-style-parser to compatible with old and new format.

* build(example-scripts): remove webpack.NamedModulesPlugin

webpack.NamedModulesPlugin was deprecated in v4 and removed in v5.
these plugin are default in devlopment mode and should not be configured in production mode,
because it will expose file path and increase bundle sizes.

https://v4.webpack.js.org/migrate/4/#deprecatedremoved-plugins

* chore(examples): update vue3 assets

---------

Co-authored-by: zealotchen <92966734+zealotchen0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants