turbo
turbo copied to clipboard
Fixed prisma example to allow importing interfaces from database
For context:
https://twitter.com/javier_dev/status/1592532624635199489
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated |
|---|---|---|---|---|
| examples-designsystem-docs | 🔄 Building (Inspect) | Nov 15, 2022 at 3:02PM (UTC) | ||
| turbo-site | ✅ Ready (Inspect) | Visit Preview | 💬 Add your feedback | Nov 15, 2022 at 3:02PM (UTC) |
5 Ignored Deployments
| Name | Status | Preview | Comments | Updated |
|---|---|---|---|---|
| examples-basic-web | ⬜️ Ignored (Inspect) | Nov 15, 2022 at 3:02PM (UTC) | ||
| examples-kitchensink-blog | ⬜️ Ignored (Inspect) | Nov 15, 2022 at 3:02PM (UTC) | ||
| examples-native-web | ⬜️ Ignored (Inspect) | Nov 15, 2022 at 3:02PM (UTC) | ||
| examples-nonmonorepo | ⬜️ Ignored (Inspect) | Nov 15, 2022 at 3:02PM (UTC) | ||
| examples-svelte-web | ⬜️ Ignored (Inspect) | Nov 15, 2022 at 3:02PM (UTC) |
:green_circle: CI successful :green_circle:
Thanks
That was fast 😳, thank you!
Also worth mentioning that right now the Using Prisma with Turborepo guide is recommending having database package that directly exports ./index.ts:
{
"main": "./index.ts",
"types": "./index.ts"
}
While the with-prisma example uses a tsup build step, exposing ./dist/index.mjs for main and /.dist/index.d.ts for types:
See with-prisma/packages/database/package.json
It's not clear to the reader (at least to me), what's the benefit of one approach over the other.
I'm stumbling upon this tonight while trying to get build and start scripts to work for my server code (express backend)
I followed the guide in the docs, setting the main and types properties in my database package to ./index.ts
During development, everything is peachy, but the moment I need to just run the server in production mode, i get this
> [email protected] start
> node dist/index.js
/home/.../packages/database/index.ts:1
export * from '@prisma/client';
^^^^^^
SyntaxError: Unexpected token 'export'
I went the tsup path and got build and start to work, but now can't get the dev script to work, which once again begs the question... how are we supposed to use prisma as an internal package during development and when it comes time to actually run the app in production? At least with an express backend.
Here's a sample of what I'm getting with my dev script in the server. I've followed almost everything from the example in the repo when it comes to the prisma code. I'm using nodemon src/index.ts for server:dev
server:dev: /home/.../node_modules/ts-node/src/index.ts:859
server:dev: return new TSError(diagnosticText, diagnosticCodes, diagnostics);
server:dev: ^
server:dev: TSError: ⨯ Unable to compile TypeScript:
server:dev: ../../packages/database/dist/index.js(6,20): error TS7006: Parameter 'to' implicitly has an 'any' type.
server:dev: ../../packages/database/dist/index.js(6,24): error TS7006: Parameter 'from' implicitly has an 'any' type.
...
It's also worth noting that I got a bunch of errors when doing anything other than export * from '@prisma/client' in packages/database/src/index.ts
Is there any update on this?
I cannot get the latest version of Prisma to work in production if I follow the guide on the site and can't get it to work in development if I follow the with-prisma example in the examples.
Has anyone been able to get Prisma to work with an express backend and svelte+rollup frontend?
I believe I might have found a solution that might be worth a try for those using a plain express backend.
Thanks to this article in the Fix module resolution for development and production section, I was able to make use of Node's conditional exports to resolve everything correctly for both dev and prod, while using as minimal a setup as the site's guide proposes.
If any of this could be done better, I'm all ears. I'm very much a novice with turborepo and monorepos in general.
packages/database/package.json
{
"name": "database",
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
".": {
"prod": "./dist/index.js",
"default": "./src/index.ts"
}
},
"scripts": {
"build": "tsc",
...
}
...
}
packages/database/src/index.ts
export * from '@prisma/client';
apps/server/package.json
{
...
"scripts": {
"start": "node --conditions=prod dist/index.js",
"build": "tsc",
"dev": "nodemon src/index.ts"
},
...
}
package.json
{
"name": "root",
"private": true,
"workspaces": [
"packages/*",
"apps/*"
],
"scripts": {
"dev": "npm run up & npx turbo dev",
"build": "npx turbo build",
"start": "export NODE_ENV=production && npx turbo start",
"up": "docker-compose up",
...
},
...
}
turbo.json
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"start": {
"cache": false,
"dependsOn": [
"^db:generate",
"build"
]
},
"dev": {
"dependsOn": [
"^db:generate"
],
"cache": false
},
"build": {
"dependsOn": [
"^db:generate",
"^build"
],
"outputs": [
"dist/**",
"build/**",
"vender/**"
]
},
"db:generate": {
"cache": false
},
"db:push": {
"cache": false
}
}
}