gpt4 book ai didi

node.js - 无法获取 Node 或 ts-node/register 来再使用 es2020(flatMap 不是函数)

转载 作者:太空宇宙 更新时间:2023-11-03 23:52:40 25 4
gpt4 key购买 nike

尽管以前可以在我的代码中使用,但我无法将平面 map 与 Node 或 ts-node 一起使用。我不确定发生了什么变化,但我收到此错误 'TypeError: [x].flatMap is not a function' flatMap() 应该是一个函数,因为我明确地将 x 设为一个数组(此代码在没有问题之前可以正常工作)。

这是我的 tsconfig.json

{
"compilerOptions": {
"moduleResolution": "node",
"target": "es2020",
"esModuleInterop": true,
"sourceMap": true,
"strictNullChecks": true,
"outDir": "out",
//"strictBindCallApply": true,
//"strict": true
}
}

这是我的兰彻

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/src/main.ts",
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: build",
"runtimeArgs": ["-r", "esm"],
"stopOnEntry": true,
"console": "integratedTerminal",
},
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"--require",
"esm",
"--require",
"ts-node/register",
"--project",
"${workspaceFolder}/tsconfig.json",
"${workspaceFolder}/**/*spec.ts"
],
"console": "integratedTerminal",
"stopOnEntry": false,
}
]
}

以及有问题的平面 map 调用

(x: discord.Message | discord.Message[] | null): (discord.Message | null)[] => [x].flatMap(
// @ts-ignore
(t: discord.Message | discord.Message[] | null): (discord.Message | discord.Message[] | null) => t
)

另一个不起作用的例子:

const test = [1,3,4,[5,4,2]].flatMap(x => x);

类型错误:[1,3,4,[5,4,2]].flatMap 不是函数

ts-node/register 或 ts-node 似乎都不再尊重 "target": "es2020" 了,我不确定到底发生了什么变化。 VScode 确实有 flatMap 的智能感知上下文。谁能向我解释一下为什么它不再起作用了?

最佳答案

问题是我在安装程序后遇到了 Node 版本号冲突。我已经停止使用node的snap包,开始使用nvm了。

关于node.js - 无法获取 Node 或 ts-node/register 来再使用 es2020(flatMap 不是函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58758731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com