Problems with nodejs typescript – tsconfig file

huangapple go评论75阅读模式
英文:

Problems with nodejs typescript - tsconfig file

问题

TSError: ⨯ 无法编译TypeScript:
错误 TS5023:未知的编译器选项'allowImportingTsExtensions'。

    at createTSError (/home/minh/Documents/Detech/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/minh/Documents/Detech/node_modules/ts-node/src/index.ts:863:19)
    at createFromPreloadedConfig (/home/minh/Documents/Detech/node_modules/ts-node/src/index.ts:874:36)
    at phase4 (/home/minh/Documents/Detech/node_modules/ts-node/src/bin.ts:543:44)
    at bootstrap (/home/minh/Documents/Detech/node_modules/ts-node/src/bin.ts:95:10)
    at Object.<anonymous> (/home/minh/Documents/Detech/node_modules/ts-node/src/child/child-entrypoint.ts:24:10)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12) {
  diagnosticCodes: [ 5023 ]
}
英文:
TSError: ⨯ Unable to compile TypeScript:
error TS5023: Unknown compiler option &#39;allowImportingTsExtensions&#39;.

    at createTSError (/home/minh/Documents/Detech/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/minh/Documents/Detech/node_modules/ts-node/src/index.ts:863:19)
    at createFromPreloadedConfig (/home/minh/Documents/Detech/node_modules/ts-node/src/index.ts:874:36)
    at phase4 (/home/minh/Documents/Detech/node_modules/ts-node/src/bin.ts:543:44)
    at bootstrap (/home/minh/Documents/Detech/node_modules/ts-node/src/bin.ts:95:10)
    at Object.&lt;anonymous&gt; (/home/minh/Documents/Detech/node_modules/ts-node/src/child/child-entrypoint.ts:24:10)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12) {
  diagnosticCodes: [ 5023 ]
}

This is the error when I put allowImportingTsExtensions: true to tsconfig file before run server.

If I do not put that line to tsconfig in, all other files I import with *.ts throw an error in VSCode. The server can run normally though.

Below is the error in VSCode when I don't use allowImportingTsExtensions

> An import path can only end with a .ts extension when allowImportingTsExtensions is enabled.

If I put it in the error in VSCode is clear but the server is crash.
If I do not, The VSCode throws an error but the server still running.

Versions:

&quot;ts-node&quot;: &quot;^10.9.1&quot;,
&quot;typescript&quot;: &quot;^4.9.4&quot;,

tsconfig file:

{
  &quot;compilerOptions&quot;: {
    // &quot;allowImportingTsExtensions&quot;: true,

    &quot;rootDir&quot;: &quot;./src&quot;,
    &quot;outDir&quot;: &quot;./dist&quot;,
    &quot;baseUrl&quot;: &quot;./src&quot;,
     &quot;paths&quot;: {
      &quot;@app/*&quot;: [&quot;./*&quot;],
      &quot;@common/*&quot;: [&quot;common/*&quot;],
     },
      &quot;plugins&quot;: [
        { &quot;transform&quot;: &quot;typescript-transform-paths&quot; }
      ],
    &quot;target&quot;: &quot;es5&quot;,
    &quot;module&quot;: &quot;ESNext&quot;,
    &quot;lib&quot;: [&quot;es6&quot;],
    &quot;moduleResolution&quot;: &quot;node&quot;,
    &quot;esModuleInterop&quot;: true,
    &quot;forceConsistentCasingInFileNames&quot;: true,
    &quot;strict&quot;: true,
    &quot;skipLibCheck&quot;: true,
    &quot;resolveJsonModule&quot;: true,
    &quot;experimentalDecorators&quot;: true,
    &quot;allowSyntheticDefaultImports&quot;: true,
    &quot;allowJs&quot;: true,    
    &quot;incremental&quot;: true,
    &quot;declaration&quot;: true,
    &quot;noEmit&quot;: true,
    &quot;jsx&quot;: &quot;react&quot;
  },
  &quot;ts-node&quot;: {
    &quot;esm&quot;: true,
    &quot;transpileOnly&quot;: true,
    &quot;swc&quot;: true,
    &quot;require&quot;: [ 
     &quot;typescript-transform-paths/register&quot;,
     &quot;tsconfig-paths/register&quot;
    ],
    
  },
  &quot;include&quot;: [&quot;src/**/*.ts&quot;,&quot;./&quot;,&quot;src/*.ts&quot;],
  &quot;exclude&quot;: [&quot;node_modules&quot;],
}

答案1

得分: 2

我只是通过将TypeScript更新到版本5来解决了这个问题。谢谢大家。

英文:

I just solve the problem by update typescript to version 5. Thanks all

huangapple
  • 本文由 发表于 2023年4月17日 13:51:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032047.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定