【发布时间】:2022-10-23 04:42:14
【问题描述】:
我正在更新我的项目以使用 turborepo,但我遇到了 turbo/no-undeclared-env-vars 的奇怪行为。
在启动项目中,我从环境变量中添加了一个 hello 常量:
export default function Web() {
const hello = process.env.HELLO;
return (
<div>
<h1>{hello}</h1>
<Button />
</div>
);
}
在运行npm run lint 时,我得到了预期的错误:
web:lint: ./pages/index.tsx
web:lint: 4:17 Error: $HELLO is not listed as a dependency in turbo.json turbo/no-undeclared-env-vars
但是当我将它添加到 turbo.json 并重新运行 npm run lint 时,它仍然显示错误。
{
"$schema": "https://turborepo.org/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build", "$HELLO"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
}
它似乎正在使用缓存,因为如果我从 apps/web/.next/.cache/.eslint 中删除缓存并再次运行它,它就不再显示错误了。
它也以另一种方式工作。
如果我现在从turbo.json 中删除$HELLO 并再次运行npm run lint,它会说没有错误,而应该说它是未列出的。同样在这里,手动删除缓存再次显示它,但在我看来它应该自动检测它,不是吗?
我还尝试更新 turbo.json 在 lint 期间不要使用缓存,但这也无济于事:
{
"$schema": "https://turborepo.org/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build", "$HELLO"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"outputs": [],
"cache": false
},
"dev": {
"cache": false
}
}
}
有什么建议么?
【问题讨论】: