-
The documentation on server is only about js. First I just copied the code in documentation into "server.js", but it failed because games are defined in typescript and js cannot import typescript modules. Then I change it to "server.ts", but now I don't know how to run this. So how to use server with typescript? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
You need to build typescript first. Please refer to this project for more
detail.
https://github.com/averycrespi/thinktank
https://github.com/averycrespi/thinktank/blob/f72fd089edaf5bc04b6600995065589a383c4703/package.json#L44
…On Mon, Dec 21, 2020 at 7:16 AM 隔壁的泰山233 ***@***.***> wrote:
The documentation on server is only about js.
First I just copied the code in documentation into "server.js", but it
failed because games are defined in typescript and js cannot import
typescript modules.
Then I change it to "server.ts", but now I don't know how to run this.
So how to use server with typescript?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#874>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKAIMGLCUZUKBE2LGZDVRG3SV2AVZANCNFSM4VDOX4DQ>
.
|
Beta Was this translation helpful? Give feedback.
-
As @larry801 says, you need to compile the One other option is to use something like |
Beta Was this translation helpful? Give feedback.
-
I faced the same issue and spent a lot of time searching for a solution, but couldn't find any helpful information. packages.json {
...
"type": "module",
"scripts": {
...
"build:server": "tsc -p tsconfig.server.json && echo '{ \"type\": \"commonjs\" }' > build/server/package.json",
"start:server": "node build/server/server.js",
... tsconfig.server.json {
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node10",
"noEmit": false,
"outDir": "build/server/"
},
"include": ["app/server.ts"]
} Since There may be a more elegant solution, so I hope someone can use this as a reference to further optimize it. |
Beta Was this translation helpful? Give feedback.
As @larry801 says, you need to compile the
.ts
file to plain JavaScript before running it with Node.One other option is to use something like
ts-node
, which allows you to transpile and run from a single command (likets-node ./server.ts
). There are some limitations with ES modules, so you may need to tweaktsconfig.json
to get this working correctly.