genyus
genyus
WWasp
Created by genyus on 12/16/2024 in #đŸ™‹questions
Accessing static files
I need my app to access a collection of static JSON Schema files, but it doesn't seem straightforward to do so. The files are currently positioned in the server/utils/schemas directory, but this directory isn't included in .wasp/out/sdk/wasp/dist/ext-src. It is included in .wasp/out/sdk/ext-src, which is where I'm currently having to reference them from, but I suspect this location won't be valid for the deployed application. As the __directory and __file magic variables aren't available, here's my current, hacky, implementation:
export function getSchema(model: string): any {
const schemaPath = path.join(dirname(fileURLToPath(import.meta.url)), '../../sdk/wasp/ext-src/server/utils/schemas', `${model}.schema.json`);

try {
return JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
} catch (error) {
throw new Error(`Error reading or parsing schema file: ${error}`);
}
}
export function getSchema(model: string): any {
const schemaPath = path.join(dirname(fileURLToPath(import.meta.url)), '../../sdk/wasp/ext-src/server/utils/schemas', `${model}.schema.json`);

try {
return JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
} catch (error) {
throw new Error(`Error reading or parsing schema file: ${error}`);
}
}
What's the accepted best practise to accomplish this?
19 replies
WWasp
Created by genyus on 12/5/2024 in #đŸ™‹questions
Broken generator
I'm attempting to configure a third-party generator in my instance. On the first attempt, setting provider = prisma-docs-generator produces the following compilation error:
[ Db ] Environment variables loaded from .env
[ Db ] Prisma schema loaded from ../db/schema.prisma
[ Db !] Error: Generator "prisma-docs-generator" failed:
[ Db !]
[ Db !] /bin/sh: prisma-docs-generator: command not found
[ Db !]
[ Db ] Environment variables loaded from .env
[ Db ] Prisma schema loaded from ../db/schema.prisma
[ Db !] Error: Generator "prisma-docs-generator" failed:
[ Db !]
[ Db !] /bin/sh: prisma-docs-generator: command not found
[ Db !]
Then a bit more digging online led me to try changing it to provide = node node_modules/prisma-docs-generator, but that failed with the following error:
[ Db ] Environment variables loaded from .env
[ Db ] Prisma schema loaded from ../db/schema.prisma
[ Db !] Error: Generator "node node_modules/prisma-docs-generator" failed:
[ Db !]
[ Db !] node:internal/modules/cjs/loader:1249
[ Db !] throw err;
[ Db !] ^
[ Db !] Error: Cannot find module 'web/app/.wasp/out/server/node_modules/prisma-docs-generator'
[ Db !] at Function._resolveFilename (node:internal/modules/cjs/loader:1246:15)
[ Db !] at Function._load (node:internal/modules/cjs/loader:1072:27)
[ Db !] at TracingChannel.traceSync (node:diagnostics_channel:322:14)
[ Db !] at wrapModuleLoad (node:internal/modules/cjs/loader:216:24)
[ Db !] at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
[ Db !] at node:internal/main/run_main_module:36:49 {
[ Db !] code: 'MODULE_NOT_FOUND',
[ Db !] requireStack: []
[ Db !] }
[ Db !] Node.js v23.1.0
[ Db ] Environment variables loaded from .env
[ Db ] Prisma schema loaded from ../db/schema.prisma
[ Db !] Error: Generator "node node_modules/prisma-docs-generator" failed:
[ Db !]
[ Db !] node:internal/modules/cjs/loader:1249
[ Db !] throw err;
[ Db !] ^
[ Db !] Error: Cannot find module 'web/app/.wasp/out/server/node_modules/prisma-docs-generator'
[ Db !] at Function._resolveFilename (node:internal/modules/cjs/loader:1246:15)
[ Db !] at Function._load (node:internal/modules/cjs/loader:1072:27)
[ Db !] at TracingChannel.traceSync (node:diagnostics_channel:322:14)
[ Db !] at wrapModuleLoad (node:internal/modules/cjs/loader:216:24)
[ Db !] at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
[ Db !] at node:internal/main/run_main_module:36:49 {
[ Db !] code: 'MODULE_NOT_FOUND',
[ Db !] requireStack: []
[ Db !] }
[ Db !] Node.js v23.1.0
What is the correct way to include additional generators?
14 replies