微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法让 ts-node 编译带有可选链接的代码

如何解决无法让 ts-node 编译带有可选链接的代码

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

Bellow 希望一切都相关。 (命令是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)

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。