无法再使节点或ts-node / register使用es2020(flatMap不是函数)

时间:2019-11-08 00:23:17

标签: node.js typescript visual-studio-code mocha tsconfig

尽管以前可以在我的代码中使用,但我无法将平面图与node或ts-node一起使用。我不确定发生了什么变化,但是我得到这个错误(int*)(&array+1) flatMap()应该是一个函数,因为我明确地将x设为一个数组(此代码在没有问题的情况下就可以正常工作了。)

这是我的tsconfig.json

'TypeError: [x].flatMap is not a function'

这是我的主人

{
    "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,
        }
    ]
}

另一个无效的示例:

(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);

ts-node / register或ts-node似乎都不再尊重TypeError: [1,3,4,[5,4,2]].flatMap is not a function,而且我不确定到底发生了什么变化。 VScode确实具有用于flatMap的智能感知的上下文。谁能向我解释为什么它不再起作用了?

1 个答案:

答案 0 :(得分:1)

问题是安装程序后我的节点版本号有冲突。我已经停止使用node的snap软件包,而开始使用nvm。