0

我正在使用 Next.js 和 TypeScript 构建一个 Web 应用程序。我有一个自定义server.ts文件。因此,我的开发命令是ts-node server.ts. 一切正常,直到现在:( 每次我尝试运行命令时,我的 tsconfig.json 文件都会更改。

我已经尝试了最基本的解决方案,例如删除node_modules目录并npm install再次运行命令或重新安装整个 Node.js。不幸的是,没有什么对我有用。

这是我的tsconfig.json文件:

{
  "compileOnSave": false,
  "compilerOptions": {
    "target": "es2017",
    "module": "esnext",
    "jsx": "preserve",
    "allowJs": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": false,
    "preserveConstEnums": true,
    "sourceMap": true,
    "skipLibCheck": true,
    "baseUrl": ".",
    "typeRoots": [
      "./types",
      "./node_modules/@types"
    ],
    "lib": [
      "dom",
      "esnext"
    ],
    "outDir": "dist/",
    "incremental": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "include": [
    "pages/*",
    "components/*",
    "server.ts"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "**/*.spec.tsx",
    "**/*.test.ts",
    "**/*.test.tsx",
    "jest.config.js",
    "jest.setup.js",
    "next.config.js"
  ]
}

这是我运行后收到的消息ts-node server.ts

The following changes are being made to your tsconfig.json file:
  - compilerOptions.strict to be suggested value: true (this can be changed)
  - compilerOptions.forceConsistentCasingInFileNames to be suggested value: true (this can be changed)
  - compilerOptions.esModuleInterop must be true (requirement for babel)
  - compilerOptions.module must be esnext (for dynamic import() support)
  - compilerOptions.resolveJsonModule must be true
  - compilerOptions.isolatedModules must be true (requirement for babel)
  - compilerOptions.noEmit must be true
4

1 回答 1

1

好的,我终于发现了一个问题。看起来在 Next.js v8.1.1.canary.26(拉取请求)中添加了自动 TypeScript 设置。但是,它看起来并不总是正常工作。已经存在与此新功能相关的问题。

于 2019-05-15T17:57:47.930 回答