xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

run ts file without compiling All In One

run ts file without compiling All In One

$ npx ts-node ./app.ts

ts-node

$ yarn add -D ts-node
$ yarn add -D typescript


# Depending on the configuration, you may also need these
$ yarn add -D tslib
$ yarn add -D @types/node

https://www.npmjs.com/package/ts-node

https://github.com/TypeStrong/ts-node

https://typestrong.org/ts-node/

bugs

$ npx ts-node ./567\ permutation-in-string.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/xgqfrms-mbp/Documents/GitHub/leetcode/js-solutions/567 permutation-in-string.ts

https://github.com/TypeStrong/ts-node/issues?q=TypeError+[ERR_UNKNOWN_FILE_EXTENSION]%3A+Unknown+file+extension+".ts"

https://github.com/TypeStrong/ts-node/issues/1062

https://typestrong.org/ts-node/docs/module-type-overrides/

https://stackoverflow.com/questions/63445821/ts-node-execute-typescript-with-module-import-and-module-defined

node & CJS

{
  "type": "commonjs",
}

tsc & ESM

ts-node bug

{
  "type": "module",
}

ESM vs CJS

tsconfig.json

{
  "type": "module"
}

https://thewebdev.info/2022/03/20/how-to-fix-the-uncaught-referenceerror-exports-is-not-defined-error-in-files-generated-with-typescript/

refs

https://stackoverflow.com/questions/33535879/how-to-run-typescript-files-from-command-line

https://www.educative.io/answers/how-to-execute-the-typescript-file-using-the-command-line



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-08-07 16:36  xgqfrms  阅读(80)  评论(2编辑  收藏  举报