小编Jim*_*ode的帖子

psql:错误:连接到套接字“/var/run/postgresql/.s.PGSQL.5432”上的服务器失败:致命:用户“postgres”的对等身份验证失败(Ubuntu)

当我尝试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)

postgresql ubuntu

65
推荐指数
3
解决办法
13万
查看次数

将 localStorage.getItem() 与打字稿一起使用

我有以下代码行:

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)

我是打字稿新手。它在这里寻找什么?

local-storage typescript reactjs

30
推荐指数
2
解决办法
6万
查看次数

将 jest 与 Nodejs 和 TypeScript 结合使用时出现“ReferenceError:未定义 StructuredClone”

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

node.js typescript jestjs structured-clone ts-jest

27
推荐指数
2
解决办法
4万
查看次数

尝试执行“npx typescript --init”“npm ERR!无法确定要运行的可执行文件”

错误是什么意思npm ERR! could not determine executable to run意思?

\n

我正在尝试使用打字稿和纱线初始化一个简单的nodejs应用程序。我以前从未真正使用过纱线。

\n

我运行了命令:\n yarn init\n成功创建了一个package.json\n npx typescript --init \n给了我上面的错误消息。

\n

版本:\nyarn v1.22.11\nnpx 7.12.0

\n

我跑了yarn add typescript,它给了我:

\n
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\n
Run Code Online (Sandbox Code Playgroud)\n

但当我尝试时typescript -v我得到typescript: command not found

\n

node.js npm typescript yarnpkg

13
推荐指数
2
解决办法
2万
查看次数

如何在 create-react-app 中为 index.html 指定 Cache-Control 标头

我正在尝试遵循有关 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”?我不知道如何为不同的资产设置不同的控件。

html caching reactjs create-react-app

12
推荐指数
2
解决办法
4604
查看次数

如何让 React 测试库的 userEvent 输入到输入中

我可以使用 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)

testing typescript react-testing-library

9
推荐指数
1
解决办法
1万
查看次数

将属性添加到错误对象“属性...在类型‘错误’上不存在”时出现打字稿错误

我正在尝试使用 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 构造函数具有以下可选参数:messageoptionsfileNamelineNumber- 所以我想status不应该允许?我想我是从 YouTube 教程中复制的,所以我想这实际上不是一个好的做法?

error-handling node.js express typescript

8
推荐指数
1
解决办法
5238
查看次数

如何在 VS-Code 中关闭或关闭调试模式

我在 VS Code 中打开了调试模式,现在想将其关闭,但不知道如何关闭。

我有这个浮动菜单: 在此输入图像描述

我的底部工具栏仍然是橙色的:在此输入图像描述

我如何恢复到原来的设置?(我在其他帖子上看到人们想要隐藏浮动菜单,但我想如果可能的话我想关闭调试?)

reactjs visual-studio-code vscode-debugger

7
推荐指数
2
解决办法
1万
查看次数

导入现有 .jsx 文件时“找不到模块的声明文件”

(抱歉,如果这是重复的,我找不到任何处理现有 .jsx 文件的问答)

我已经将我的应用程序迁移到打字稿,现在出现了以下错误:

Could not find a declaration file for module '../components/...'. '.../components/....js' implicitly has an 'any' type.ts(7016)

我不想现在就检查整个应用程序并将所有内容都转换为.tsx. 鉴于我现在只想忽略导入问题,我觉得在我的文件中noImplicitAny求助有点过分了。falsetsconfig

有没有更明智的方法来解决这些错误?

javascript module typescript reactjs tsconfig

7
推荐指数
1
解决办法
1836
查看次数

Ctrl+单击无法使用 Google Chrome 打开 VS Code 中的链接

我无法再在 VS Code 中打开文件中的 url。一切都表明该功能仍然存在,除了在我的浏览器中打开链接的部分之外。链接颜色发生变化,弹出窗口显示:

ctrl+单击的屏幕截图

但是当我点击时什么也没有发生?

google-chrome visual-studio-code windows-11

6
推荐指数
1
解决办法
2008
查看次数