【问题标题】:Cannot get ts-node to compile code with optional chaining无法让 ts-node 编译带有可选链接的代码
【发布时间】:2021-04-10 22:02:14
【问题描述】:

为什么要这样做?我以为我可以正常工作,但是在编写了一些带有?. 语法的代码后,它就停止了工作。我尝试更新涉及的依赖项,但无济于事。

希望下面的一切都是相关的。 (命令是npm run generate:nexus

package.json

{
  "name": "rita",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    ...
    "generate:nexus": "ts-node --transpile-only --project=./apps/server/tsconfig.nexus.json ./apps/server/src/nexus-prisma/schema.ts"
  },
  "dependencies": { ... },
  "devDependencies": { 
    ...
    "ts-node": "~9.1.0"
  },
}

tsconfig.nexus.json

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "baseUrl": ".",
        "module": "CommonJS",
        "target": "esnext",

        "outDir": "dist",
        "rootDir": "src",
        "lib": ["esnext"],
        "esModuleInterop": true,
        "strict": true,
        "typeRoots" : [
            "node_modules/@types",
            "./src/nexus-prisma/nexus.generated.ts",
        ],

        //"extendedDiagnostics": true,
        //"noEmit": true,
    },
    "files": [
        "./src/nexus-prisma/schema.ts",
    ],
}

错误:

ts-node --transpile-only --project=./apps/server/tsconfig.nexus.json ./apps/server/src/nexus-prisma/schema.ts        

C:\project\apps\server\src\nexus-prisma\auth\maps.ts:47
            districts: helpers_1.sanitizeParamList(query, 'f-d')?.map(v => +v),
                                                                 ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:1072:16)
    at Module._compile (internal/modules/cjs/loader.js:1122:27)
    at Module.m._compile (C:\project\node_modules\ts-node\src\index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Object.require.extensions.<computed> [as .ts] (C:\project\node_modules\ts-node\src\index.ts:1059:12)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\project\apps\server\src\nexus-prisma\schema\carriers-of-offer\offer.ts:2:1)

【问题讨论】:

  • 尝试将target 更改为es2019es2020
  • 参考herehere。和here。所有人的答案都一样
  • tldr;这不是 TS 错误,而是运行时 nodeJS 错误。目标必须是 es2019 或更低。

标签: typescript nexus nexus-prisma


【解决方案1】:

没有编译错误,错误是使用的节点不支持.?可选链。

【讨论】:

    猜你喜欢
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 2021-07-01
    相关资源
    最近更新 更多