Execute custom typescript file with ts-node and sveltekit imports #9807
-
I'm using prisma and I have a seed.ts file that loads data into my database for testing. In that file I'd like to do things like
Notice I'm importing using the $lib alias. Unfortunately when I urn the script using ts-node this import is not found. It also doesn't work if I use a relative import without the alias e.g. What do I need to do so my imports will work in my custom scripts? I added a seed command (
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I have the exact same probem |
Beta Was this translation helpful? Give feedback.
-
Use vite-node: {
"scripts": {
"seed": "vite-node --options.transformMode.ssr='/.*/' src/lib/util/seed.ts"
},
"devDependencies": {
"vite-node": "^0.30.1"
}
}
|
Beta Was this translation helpful? Give feedback.
-
this solution works but still errors when using the .env |
Beta Was this translation helpful? Give feedback.
Use vite-node:
--options.transformMode.ssr='/.*/'
makes sure that vite runs this code as a server, rather than a client. You need this to be able to access private env variables.