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

TypeError: Cannot read properties of undefined (reading 'endsWith') #92

Open
Volcanic-Penguin opened this issue Mar 5, 2022 · 5 comments

Comments

@Volcanic-Penguin
Copy link

Volcanic-Penguin commented Mar 5, 2022

Hello!

I really like the idea of writing TypeScript code and compiling it to GDScript code, unfortunately I'm having issues getting it to run.

At first I got the error :

Error: Cannot find module 'typescript'

So I figured I needed to install TypeScript globally, which fixed the issue:

npm install --global typescript

In the past I've always used TypeScript with Vue or React in a CLI created project so I didn't have TypeScript installed globally. I figure this should probably be mentioned in the README.

But now I'm getting a more obscure error:

C:\Users\XXXXX\AppData\Roaming\npm\node_modules\ts2gd\js\project\generate_dynamic_defs\build_group_types.js:15
                groupNameToTypes[group] ??= new Set();
                                        ^^^

SyntaxError: Unexpected token '??='
    at wrapSafe (internal/modules/cjs/loader.js:988:16)
    at Module._compile (internal/modules/cjs/loader.js:1036:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (C:\Users\XXXXX\AppData\Roaming\npm\node_modules\ts2gd\js\project\project.js:15:29)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)

I have no idea what this operator is supposed to be doing, and neither does my version of Node.

@Volcanic-Penguin
Copy link
Author

Volcanic-Penguin commented Mar 5, 2022

Ok I updated my version of Node from v14.17.6 to v16.14.0 and this fixed the issue. I figure this should probably also be mentioned in the README.

Running ts2gd --init now works well, however when running ts2gd I'm now getting another error:

ts2gd v0.0.35 - Scanning project...
C:\Users\XXXXX\AppData\Roaming\npm\node_modules\ts2gd\js\project\project.js:76  
        if (path.endsWith(".ts")) {
                 ^

TypeError: Cannot read properties of undefined (reading 'endsWith')
    at TsGdProjectClass.createAsset (C:\Users\XXX\AppData\Roaming\npm\node_modules\ts2gd\js\project\project.js:76:18)
    at new TsGdProjectClass (C:\Users\XXXXX\AppData\Roaming\npm\node_modules\ts2gd\js\project\project.js:39:34)
    at Object.makeTsGdProject (C:\Users\XXXXX\AppData\Roaming\npm\node_modules\ts2gd\js\project\project.js:271:12)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.main (C:\Users\XXXXX\AppData\Roaming\npm\node_modules\ts2gd\js\main.js:204:19)

It looks like there's something with my folder structure that makes path sometimes undefined?

@Volcanic-Penguin Volcanic-Penguin changed the title SyntaxError: Unexpected token '??=' TypeError: Cannot read properties of undefined (reading 'endsWith') Mar 5, 2022
@ksjogo
Copy link
Contributor

ksjogo commented Mar 8, 2022

Hi,
Current master was never tested on Windows.
Only with my #82 I was able to run it.
That one is available on npm as https://www.npmjs.com/package/@kronbergerspiele/ts2gd
Could you check if that performs better?

@Volcanic-Penguin
Copy link
Author

Hey ksjogo!

Thanks for the help!

I tried out your fork and it definitely works better, but with some bugs.

  1. It seems to ignore the ts2gd.json file defining the source and destination folders, and instead just generates the Godot code file in the same directory as the TypeScript file.
  2. The Godot code file doesn't have a file extension, test.ts becomes test
  3. Making changes to the TypeScript file while running the watcher does trigger a recompile, however it seems to still compile the old code instead of the new changes.

@ksjogo
Copy link
Contributor

ksjogo commented Mar 9, 2022

Don't have access to my Windows machine till the weekend, will take a look then.
Do you have a sample repo with these errors?
When I was running it against my game on Windows it seemed to behave fine.
I decided to just use GDScript now though, it's just easier and quicker.

@Volcanic-Penguin
Copy link
Author

Volcanic-Penguin commented Mar 9, 2022

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

2 participants