当我尝试psql使用此命令打开时:
psql -U postgres
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres"
Run Code Online (Sandbox Code Playgroud)
但当我使用时它连接成功:
sudo -u postgres psql
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下发生了什么以及如何诊断/解决这个问题吗?我的pg_hba.conf包含以下内容:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256 …Run Code Online (Sandbox Code Playgroud) 我有以下代码行:
const allGarments = teeMeasuresAverages || JSON.parse(localStorage.getItem("teeMeasuresAverages")) || teeMeasuresAveragesLocal;
Run Code Online (Sandbox Code Playgroud)
Typescript 抛出此警告:
Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.
Run Code Online (Sandbox Code Playgroud)
所以我尝试包含非空断言运算符(!):
Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.
Run Code Online (Sandbox Code Playgroud)
然后这给了我一个不同的警告:
Forbidden non-null assertion.
Run Code Online (Sandbox Code Playgroud)
我是打字稿新手。它在这里寻找什么?
jest我正在使用打字稿的简单 NodeJS 应用程序中运行测试。我的测试抛出一个错误:ReferenceError: structuredClone is not defined。
我没有收到任何 linter 错误,并且代码可以正常编译。
const variableForValidation = structuredClone(variableForValidationUncloned);
Run Code Online (Sandbox Code Playgroud)
包.json:
"dependencies": {
...
},
"devDependencies": {
"@types/jest": "^29.0.0",
"@types/node": "^18.7.15",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"eslint": "^8.23.0",
"jest": "^28.0.1",
"nodemon": "^2.0.19",
"serverless-plugin-typescript": "^2.1.2",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.8.2"
}
Run Code Online (Sandbox Code Playgroud)
这个github问题向我表明问题已经解决:https://github.com/facebook/jest/issues/12628 - 或者也许我误解了?
我见过类似的 Stack 问题,但使用 Mocha: mocha not recognize StructuredClone is not Defined
错误是什么意思npm ERR! could not determine executable to run意思?
我正在尝试使用打字稿和纱线初始化一个简单的nodejs应用程序。我以前从未真正使用过纱线。
\n我运行了命令:\n yarn init\n成功创建了一个package.json\n npx typescript --init \n给了我上面的错误消息。
版本:\nyarn v1.22.11\nnpx 7.12.0
\n我跑了yarn add typescript,它给了我:
info Direct dependencies\n\xe2\x94\x94\xe2\x94\x80 typescript@4.3.5\ninfo All dependencies\n\xe2\x94\x94\xe2\x94\x80 typescript@4.3.5\nRun Code Online (Sandbox Code Playgroud)\n但当我尝试时typescript -v我得到typescript: command not found
我正在尝试遵循有关 create-react-app.dev 的生产构建文档的指导:
为了向您的用户提供最佳性能,最佳做法是为 index.html 以及 build/static 中的文件指定 Cache-Control 标头。此标头允许您控制浏览器和 CDN 缓存静态资产的时间长度。如果您不熟悉 Cache-Control 的作用,请参阅这篇文章以获得很好的介绍。
将 Cache-Control: max-age=31536000 用于您的构建/静态资产,以及 Cache-Control: no-cache 用于其他所有内容是一个安全有效的起点,可确保您的用户浏览器始终检查更新的 index.html 文件,并将缓存所有构建/静态文件一年。请注意,您可以安全地使用 build/static 上的一年到期时间,因为文件内容哈希已嵌入到文件名中。
这样做的正确方法是在 index.html 中使用 HTML 标头 - 例如:
<meta http-equiv="Cache-Control" content="max-age: 31536000, no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
Run Code Online (Sandbox Code Playgroud)
(信用:此堆栈溢出响应和此 YouTube 教程)
如果是这样,我该如何遵循文档的建议,即我应该为您的构建/静态资产设置“max-age=31536000,并为其他所有内容设置 Cache-Control: no-cache”?我不知道如何为不同的资产设置不同的控件。
我可以使用 React 测试库的方法成功实现测试fireEvent,但是当我尝试使用等效测试时,userEvent我无法让它触发任何内容。我怎样才能解决这个问题?
/MyInput.tsx
import { useState } from "react";
export default function MyInput() {
const [inputTextState, setInputTextState] = useState("");
return (
<div>
<label>
My Input
<input
value={inputTextState}
onChange={(event) => setInputTextState(event.target.value)}
/>
</label>
<p>{inputTextState}</p>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
__tests__/MyInput.test.tsx
import { fireEvent, render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import MyInput from "../MyInput";
const setup = () => {
const utils = render(<MyInput />);
const input = utils.getByLabelText("My Input") as HTMLInputElement;
return {
input,
...utils …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Node/Express 应用程序转向打字稿。以前我的代码是:
//app.js
const error = new Error('Not Found');
error.status = 404;
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时:
//app.ts
const error = new Error('Not Found');
error.status = 404; // Property 'status' does not exist on type 'Error'.ts(2339)
Run Code Online (Sandbox Code Playgroud)
我从developer.mozilla.org 文档中了解到,Error 构造函数具有以下可选参数:message、options、fileName、lineNumber- 所以我想status不应该允许?我想我是从 YouTube 教程中复制的,所以我想这实际上不是一个好的做法?
我在 VS Code 中打开了调试模式,现在想将其关闭,但不知道如何关闭。
我如何恢复到原来的设置?(我在其他帖子上看到人们想要隐藏浮动菜单,但我想如果可能的话我想关闭调试?)
(抱歉,如果这是重复的,我找不到任何处理现有 .jsx 文件的问答)
我已经将我的应用程序迁移到打字稿,现在出现了以下错误:
Could not find a declaration file for module '../components/...'. '.../components/....js' implicitly has an 'any' type.ts(7016)
我不想现在就检查整个应用程序并将所有内容都转换为.tsx. 鉴于我现在只想忽略导入问题,我觉得在我的文件中noImplicitAny求助有点过分了。falsetsconfig
有没有更明智的方法来解决这些错误?
typescript ×6
reactjs ×4
node.js ×3
caching ×1
express ×1
html ×1
javascript ×1
jestjs ×1
module ×1
npm ×1
postgresql ×1
testing ×1
ts-jest ×1
tsconfig ×1
ubuntu ×1
windows-11 ×1
yarnpkg ×1