【发布时间】:2023-02-06 10:33:42
【问题描述】:
目前我已经设置了一个带有 turborepo 的 monorepo,其中 Nestjs 作为 BE,Nextjs 作为 FE。
我想重用 prisma 定义,所以很自然地我将它拆分成自己的包并实现了自己的 tsconfig。在我的数据库包的索引处(棱镜所在的位置),我有这个简单的代码:
export * from "@prisma/client";
我的后端和前端现在都具有相同的依赖项:
backend -> database和frontend -> database
我的 FE 编译正常,我可以使用我的 prisma 中的定义,但是 NestJS 应用程序没有在数据库包中编译 TS 并且它有这个错误,我认为它与 tsconfig 有关,似乎 NestJS(我的后端)确实如此不想编译私有包依赖项,因此它不识别“导出”。
core:dev: export * from "@prisma/client";
core:dev: ^^^^^^
core:dev:
core:dev: SyntaxError: Unexpected token 'export'
任何人都可以指出我的回购协议有什么问题吗?
在导入 nestjs 应用程序之前,我是否需要先构建数据库包?如果是这样,客户如何在不先构建的情况下工作?
这是我在server/core/tsconfig.json 中用于后端的 tsconfig:
{
"extends": "tsconfig/server.json",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./",
},
}
这是我在 apps/web/tsconfig.json 中用于前端的 tsconfig(工作正常):
{
"extends": "tsconfig/nextjs.json",
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
和扩展,
tsconfig/server.json:
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
tsconfig/nextjs.json:
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Next.js",
"extends": "./base.json",
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["src", "next-env.d.ts"],
"exclude": ["node_modules"]
}
【问题讨论】:
标签: reactjs typescript next.js nestjs turborepo