我正在使用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
答案 0 :(得分:0)
好的,我终于找到了一个问题。看起来Next.js v8.1.1.canary.26(pull request)中添加了自动TypeScript设置。但是,它似乎并不总是能正常工作。已经有一个与此新功能相关的issue。