我也刚刚遇到这个问题。据我所知,当您构建消费应用程序时,它不会从类型包中转译 Typescript。
对于 NextJS 项目,有一个 npm 包可以解决这个问题https://www.npmjs.com/package/next-transpile-modules https://www.npmjs.com/package/next-transpile-modules
但是,由于我有一个 NestJS 项目,您需要自己转译类型包。这是我的设置:
包/项目类型/package.json
{
...
// entry point is now the transpiled version of your code
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "commonjs",
"scripts": {
"build": "tsc",
...
}
包/项目类型/tsconfig.json
{
"include": ["."],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {
"module": "commonjs",
"outDir": "./dist"
}
}
应用程序/nest-project/tsconfig.json
{
...
"module": "commonjs",
...
}
然后您可以配置您的turbo.json
确保所有依赖包都已预先构建拓扑依赖性 https://turborepo.org/docs/core-concepts/pipelines#topological-dependency。来自 Turbo 文档的示例:
"pipeline": {
"build": {
// "A package's `build` command depends on its dependencies'
// and devDependencies' `build` commands being completed first"
"dependsOn": ["^build"]
}
// ... omitted for brevity
}
希望有帮助。
[Update]
Example repo https://github.com/patrickkenyon/turbo-example