ts-node 正在更改 tsconfig.json 文件
ts-node is changing tsconfig.json file
我正在使用 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"
]
}
这是我在 运行ning 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
好的,我终于找到问题了。 Next.js v8.1.1.canary.26 中似乎添加了自动 TypeScript 设置(pull request). However, it looks like it does not always work correctly. There is already an issue 与此新功能相关。
我正在使用 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"
]
}
这是我在 运行ning 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
好的,我终于找到问题了。 Next.js v8.1.1.canary.26 中似乎添加了自动 TypeScript 设置(pull request). However, it looks like it does not always work correctly. There is already an issue 与此新功能相关。