P
Prisma3w ago
Zige

Cannot run built code when different prisma client output folder

Hi, I came to this problem when I tried to change the prisma client output folder. No matter if I specify folder in src or not, it is not possible to run the build index.js. When I run it in dev, it works just fine. The build completes just fine (when I omit the --dts tag). But when I want to run it, it always fail on error something like: Error: Dynamic require of "child_process" is not supported or Error: Dynamic require of "fs" is not supported in generator schema: output = "../src/generated-prisma-client" here are my scripts:
"scripts": {
"dev": "nodemon -w src/server -x tsx src/server/index.ts",
"start:tsx": "cross-env NODE_ENV=production tsx src/server/index.ts",
"build:react": "vite build",
"build:server": "tsup",
"build": "npm run build:react && npm run build:server",
"start:node": "node dist/index.js",
},
"scripts": {
"dev": "nodemon -w src/server -x tsx src/server/index.ts",
"start:tsx": "cross-env NODE_ENV=production tsx src/server/index.ts",
"build:react": "vite build",
"build:server": "tsup",
"build": "npm run build:react && npm run build:server",
"start:node": "node dist/index.js",
},
here is my tsup config:
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["./src/server/index.ts"],
format: ["esm"],
outDir: "dist",
minify: true,
splitting: false,
sourcemap: true,
});
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["./src/server/index.ts"],
format: ["esm"],
outDir: "dist",
minify: true,
splitting: false,
sourcemap: true,
});
and here is the tsconfig:
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@prisma-client": ["./src/generated-prisma-client"],
"@prisma-client/*": ["./src/generated-prisma-client/*"]
}
},
"include": ["src/**/*"]
}
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@prisma-client": ["./src/generated-prisma-client"],
"@prisma-client/*": ["./src/generated-prisma-client/*"]
}
},
"include": ["src/**/*"]
}
I believe there is problem in the typescript building config, but honest IDK. Has anyone faced this before? Any suggestion is appreciated.
2 Replies
RaphaelEtim
RaphaelEtim3w ago
Hi @Zige Thank you for raising this question. Can you try changing the output path to point to the root node_modules folder as suggested in this previous discussion
Zige
ZigeOP3w ago
after changing it to the node_modules/@prisma/client I got this error:
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Error:
Generating client into C:\Users\honza\visnova\test\node_modules\@prisma\client is not allowed.
This package is used by `prisma generate` and overwriting its content is dangerous.

Suggestion:
In C:\Users\honza\visnova\test\prisma\schema.prisma replace:

4 output = "../node_modules/@prisma/client"
with
4 output = "../node_modules/.prisma/client"

You won't need to change your imports.
Imports from `@prisma/client` will be automatically forwarded to `.prisma/client`
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Error:
Generating client into C:\Users\honza\visnova\test\node_modules\@prisma\client is not allowed.
This package is used by `prisma generate` and overwriting its content is dangerous.

Suggestion:
In C:\Users\honza\visnova\test\prisma\schema.prisma replace:

4 output = "../node_modules/@prisma/client"
with
4 output = "../node_modules/.prisma/client"

You won't need to change your imports.
Imports from `@prisma/client` will be automatically forwarded to `.prisma/client`
after doing what the error says, it completes normally. Then I updated the paths in tsconfig and after building, I got this error: Error: Dynamic require of "fs" is not supported I even tried to remove the paths in tsconfig and import everything directly, still the same.
Want results from more Discord servers?
Add your server