Standalone CLI in t3 project

Hi! So I wrote a question a while ago about making a little script for interacting with my db through prisma (https://discordapp.com/channels/966627436387266600/1024739607553786011) I was recommended ts-node to run the file, but that doesn't work at all. I think it has something to do with es6 imports/exports but it's really cryptic and I can't find much information about it. The error message looks like this:
PS E:\Github\frazzot-portfolio> npx ts-node .\src\utils\dbUtils.ts
(node:14184) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
E:\Github\frazzot-portfolio\src\utils\dbUtils.ts:3
export {};
^^^^^^

SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1055:15)
at Module._compile (node:internal/modules/cjs/loader:1090:27)
at Module.m._compile (E:\Github\frazzot-portfolio\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Object.require.extensions.<computed> [as .ts] (E:\Github\frazzot-portfolio\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at phase4 (E:\Github\frazzot-portfolio\node_modules\ts-node\src\bin.ts:649:14)
PS E:\Github\frazzot-portfolio> npx ts-node .\src\utils\dbUtils.ts
(node:14184) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
E:\Github\frazzot-portfolio\src\utils\dbUtils.ts:3
export {};
^^^^^^

SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1055:15)
at Module._compile (node:internal/modules/cjs/loader:1090:27)
at Module.m._compile (E:\Github\frazzot-portfolio\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Object.require.extensions.<computed> [as .ts] (E:\Github\frazzot-portfolio\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at phase4 (E:\Github\frazzot-portfolio\node_modules\ts-node\src\bin.ts:649:14)
And the file is simply
console.log("Hello");

export {};
console.log("Hello");

export {};
Has anyone else ran in to problems like this? Any help, pointers or other recommendations for how I could run a .ts file in my t3 project without running the whole web app would be greatly appreciated
15 Replies
needmorewood
needmorewood3y ago
im not super familiar but I have created ts scripts and ran them with https://github.com/egoist/tsno before im pretty noob when it comes to this so someone probably has a better solution
GitHub
GitHub - egoist/tsno: node with typescript support, importing fro...
node with typescript support, importing from URL, etc. - GitHub - egoist/tsno: node with typescript support, importing from URL, etc.
Vincent Udén
Vincent Udén3y ago
Dude thank you so much. That library just worked right of the bat
needmorewood
needmorewood3y ago
no worries
Vincent Udén
Vincent Udén3y ago
No config, no error, just worked exactly as expected
needmorewood
needmorewood3y ago
egoist and antfu are god developers so if you see options from them they get it
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Vincent Udén
Vincent Udén3y ago
For sure! I just skimmed through their github page and their stuff looks really useful
needmorewood
needmorewood3y ago
holy crap i didnt realise tsup took off like it did
nexxel
nexxel3y ago
we actually use tsup in create-t3-app it is so nice
needmorewood
needmorewood3y ago
thats good to hear, seems like we secretly love Vue devs here without knowing it 😂 well egoist is doing everything these days
cje
cje3y ago
GitHub
GitHub - esbuild-kit/tsx: ⚡️ TypeScript Execute (tsx): Node.js enha...
⚡️ TypeScript Execute (tsx): Node.js enhanced with esbuild to run TypeScript &amp; ESM - GitHub - esbuild-kit/tsx: ⚡️ TypeScript Execute (tsx): Node.js enhanced with esbuild to run TypeScript &...
cje
cje3y ago
but tbh i dont know the difference between the various options
needmorewood
needmorewood3y ago
i think tsx is antfu's version that got put into an org also great tools
nexxel
nexxel3y ago
i love vue devs
needmorewood
needmorewood3y ago
one thing i miss in react from Vue is computed properties, they just seem awful in react
Want results from more Discord servers?
Add your server