无法让 ts-node 编译带有可选链接的代码
Cannot get ts-node to compile code with optional chaining
为什么要这样做?我以为我让它工作了,但是在用 ?.
语法写了一些代码之后,它停止工作了。我尝试更新涉及的依赖项但无济于事。
波纹管希望是所有相关的。 (命令是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)
没有编译错误,错误是使用的节点不支持.?
可选链接。
为什么要这样做?我以为我让它工作了,但是在用 ?.
语法写了一些代码之后,它停止工作了。我尝试更新涉及的依赖项但无济于事。
波纹管希望是所有相关的。 (命令是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)
没有编译错误,错误是使用的节点不支持.?
可选链接。