johnfn / ts2gd

💥 Compile TypeScript to GDScript for Godot
200 stars 14 forks source link

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

Open Volcanic-Penguin opened 2 years ago

Volcanic-Penguin commented 2 years ago

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 commented 2 years ago

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?

ksjogo commented 2 years ago

Hi, Current master was never tested on Windows. Only with my https://github.com/johnfn/ts2gd/pull/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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Ok great!

Sure here you go! https://github.com/Volcanic-Penguin/ts2gd-windows-test-project https://gitlab.com/lee.comstock/ts2gd-windows-test-project