我已经设置了一个基本的turborepo 项目,我想.env
在所有应用程序和一些包之间共享变量。如果我.env
在项目的根目录中设置一个文件,所有应用程序和包如何访问它们。或者根据我的要求,我是否需要.env
在所有应用程序和包中设置多个文件?
我正在尝试将多个存储库迁移到 monorepo 架构,目前正在开发使用Turborepo引导的 POC 。
我看到的问题是 ts 模块别名配置不正确。我目前有一个 ui 包,我正在尝试从中导出一个按钮组件index.tsx
(注意,VS code 没有抱怨,它认为它可以解析该模块):
但是,当我尝试构建我的应用程序时,我发现该模块实际上并未解析:
找不到模块:无法解析“@/components/Button”
我在这里不知所措,有谁知道如何使用 Turbo repo 正确配置模块别名?以下是 tsconfig.json:
{
"extends": "tsconfig/react-library.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["./components/*"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个名为项目类型的自定义包,我在包之间共享我的类型
当我将简单的类导入到我的 Nestjs 项目中时,打字稿编译得很好,但是当涉及到运行时并执行 javascript 时,它会说:
server:dev: D:\Program\net-autism\packages\project-types\index.ts:1
server:dev: export * from "./authentication";
server:dev: ^^^^^^
server:dev:
server:dev: SyntaxError: Unexpected token 'export'
server:dev: at Object.compileFunction (node:vm:352:18)
server:dev: at wrapSafe (node:internal/modules/cjs/loader:1031:15)
server:dev: at Module._compile (node:internal/modules/cjs/loader:1065:27)
server:dev: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
server:dev: at Module.load (node:internal/modules/cjs/loader:981:32)
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "project-types",
"version": "0.0.5",
"main": "./index.ts",
"types": "./index.ts",
"type": "module",
"license": "MIT",
"scripts": {
"lint": "eslint *.ts*"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-custom": "*",
"tsconfig": "*",
"typescript": "^4.5.2"
},
"dependencies": {
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2"
}
} …
Run Code Online (Sandbox Code Playgroud) 我有一个用 create React app 制作的有趣项目。我想将同一应用程序转换为浏览器扩展。这个想法迫使我将该项目设为单一存储库。因为在这两个应用程序中,我将使用相同的组件、钩子、提供程序等。
我不想使用 Lerna 或 Yarn 工作区。而且,这将是我的第一个单一仓库。我想开始使用 Turborepo。但是,我无法想象如何让它以良好的方式工作。
我的目标文件夹结构如下
我会将包文件夹中的 monorepo 依赖项导入到 apps 文件夹中存在的 apps 中。
例如;
import { useExampleHook } from '@projectname/hooks'
import { ExampleComponent } from '@projectname/components'
Run Code Online (Sandbox Code Playgroud)
如果您除了 Turborepo 之外还有其他解决方案,请随时告诉我。NPM 工作区也是一个可以接受的解决方案。但是,turborepo 由于性能更好而具有优先权。
预先感谢您的时间和答复
复制应用程序:https://github.com/uriklar/turborepo-lib-dep-lib-repro
我正在使用 Turborepo 的基本示例(nextjs 应用程序 + ui 库)
我想添加一个额外的 ui 库并让我的 ui 库依赖它。
// packages/ui/Button.tsx
import * as React from "react";
import { Button as AnotherButton} from "anotherui"
export const Button = () => {
return <><button>Boop</button><AnotherButton/></>;
};
Run Code Online (Sandbox Code Playgroud)
我anotherui
在包目录中创建了库并将其添加为依赖项,ui
如下所示:
{
"name": "ui",
"version": "0.0.0",
"main": "./index.tsx",
"types": "./index.tsx",
"license": "MIT",
"dependencies": {
"anotherui": "workspace:*"
},
"devDependencies": {
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"tsconfig": "workspace:*",
"config": "workspace:*",
"typescript": "^4.5.3"
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试构建应用程序(从web
消耗)时,我收到以下错误:Button
ui
web:build: …
Run Code Online (Sandbox Code Playgroud) 我目前正在使用带有 Turborepo 的 monorepo 将所有微服务代码存储在一个存储库中,每个存储库都有 apackage.json
和 a tsconfig.json
,所有这些代码都是用 Nodejs 编写的。
在每个中tsconfig.json
,配置都是相同的
{
"extends": "@tsconfig/node18-strictest-esm",
"compilerOptions": {
"outDir": "build",
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
"@folder-a/*": ["./folder-a/*"], // masked
"@folder-b/*": ["folder-b/*"] // masked
}
},
"exclude": ["node_modules", "build"]
}
Run Code Online (Sandbox Code Playgroud)
我有一项服务A
作为 tRPC 服务器,一项服务B
作为 tRPC 客户端。
AppRouter
当我导入from A
to的类型定义时,如果正确键入,B
类型定义就会变为any
in 。B
A
我研究了一下并发现了类似的问题,看起来路径别名可能会导致这个问题。
有没有任何解决方案/替代原因
编辑:可以轻松重现问题的存储库:
\nhttps://github.com/sebastiangug/turborepo-nestjs
\n我有一个turborepo 项目,其中有几个共享各种包的nestjs 应用程序。
\n我已将其配置为通过 CLI 根据文档和最新版本使用 webpack。不幸的是,它似乎没有按预期编译应用程序,导致从 /packages/ 内的共享包中抛出的“意外令牌导出”。
\n我的包管理是pnpm
.
错误:
\ngraphql-server:build: SyntaxError: Unexpected token \'export\'\ngraphql-server:build: at Object.compileFunction (node:vm:352:18)\n
Run Code Online (Sandbox Code Playgroud)\n版本/依赖项:
\ngraphql-server:build: SyntaxError: Unexpected token \'export\'\ngraphql-server:build: at Object.compileFunction (node:vm:352:18)\n
Run Code Online (Sandbox Code Playgroud)\n生产版本会抛出相同的错误,并将所有内容捆绑到一个 server.js 文件中。对于 HMR,使用文档中的此配置:
\n "dependencies": {\n "@nestjs/common": "9.0.8",\n "@nestjs/core": "9.0.8",\n "@nestjs/platform-express": "9.0.8",\n "@nestjs/graphql": "10.0.21",\n "@nestjs/apollo": "10.0.19",\n "graphql": "16.5.0",\n "apollo-server-express": "3.6.7",\n "reflect-metadata": "0.1.13",\n "rimraf": "3.0.2",\n "rxjs": "7.5.5"\n },\n "devDependencies": {\n "@nestjs/cli": "8.2.8",\n "@nestjs/schematics": "8.0.11",\n "@nestjs/testing": "9.0.8",\n "@types/express": "4.17.13",\n "@types/jest": …
Run Code Online (Sandbox Code Playgroud) 我创建了一个 Turborepo 测试项目,我想尝试在 Turborepo 根目录中设置的 ESlint 配置是否适用于我的 /apps 文件夹中的所有项目,结果发现它对我不起作用......我在哪里搞砸了向上 ?我正在关注这篇文章。
/packages/esling-config-custom/index.js
module.exports = {
extends: ["next", "turbo", "prettier"],
rules: {
"no-console": 2,
"@next/next/no-html-link-for-pages": "off",
},
};
Run Code Online (Sandbox Code Playgroud)
.eslintrc.js(Turborepo 的根目录)
module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ["custom"],
settings: {
next: {
rootDir: ["apps/*/"],
},
},
};
Run Code Online (Sandbox Code Playgroud)
/apps/testing-app/.eslintrc.js
module.exports = {
...require("eslint-config-custom/index"),
parserOptions: {
tsconfigRootDir: __dirname,
project: "./tsconfig.json",
},
};
Run Code Online (Sandbox Code Playgroud)
/apps/testing-app/package.json
{
"name": "testing-app",
"version": "0.0.0",
"private": true,
"scripts": …
Run Code Online (Sandbox Code Playgroud) 我无法解决标题中提到的错误:
错误:$VARIABLE 未在 Turbo.json 中列为依赖项
当我运行 npm run build 时,我收到两个变量的错误,而不是所有变量的错误,这对我来说很奇怪......
Error: $NEXT_STRIPE_SK is not listed as a dependency in turbo.json turbo/no-undeclared-env-vars
Error: $NEXT_PUBLIC_STRIPE_PK is not listed as a dependency in turbo.json turbo/no-undeclared-env-vars
Run Code Online (Sandbox Code Playgroud)
涡轮.json
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
},
"order#build": {
"dependsOn": [
"^build"
],
"env": [
"NEXT_PUBLIC_STRIPE_PK",
"NEXT_STRIPE_SK"
],
"outputs": [
".next/**"
]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
},
"globalEnv": [
"NEXT_PUBLIC_SUPABASE_URL", …
Run Code Online (Sandbox Code Playgroud) 错误与代码库有关(我正在使用的代码库monorepo
位于vercel.json
根目录中)。在vercel.js
与react
应用程序一起打包后,一切工作正常。
我有一个简单的React.js
应用程序,带有wouter
基于 - 的路由和Vercel
部署,这让我遇到了一个小问题,我不知道解决方案。404
它总是在刷新(子页面)后返回。
我的代码看起来有点像这样。
<>
<Route path='/' component={Intro} />
<Route path='/dashboard' component={Dashboard} />
</>
Run Code Online (Sandbox Code Playgroud)
<Intro />
我<Link />
必须/dashboard
将我转到哪个<Dashboard />
页面。它确实可以在我的本地计算机、容器中以及基于 Linux 的部署中运行,但在vercel
部署中却无法真正运行,即使我尝试通过vercel.json
.
<>
<Route path='/' component={Intro} />
<Route path='/dashboard' component={Dashboard} />
</>
Run Code Online (Sandbox Code Playgroud)
还尝试了替代版本rewrites
,但仍然存在相同的问题。
{
"github": {
"silent": true
},
"rewrites": [
{
"source": "(.*)",
"destination": "/index.html"
}
]
}
Run Code Online (Sandbox Code Playgroud)
此处提供的实时部署链接:pointrest-6ttd9zep8-araclx.vercel.app …