使用Bun创建Next.js应用时出现tsconfig.json缺失错误
解决Bun创建Next.js应用时tsconfig.json缺失的问题
修复步骤
1. 指定稳定版Next.js创建
create-next-app最新版本可能和Bun存在兼容问题,试试指定一个稳定版本执行创建命令:
bun create next-app@13.5.6 my-app
2. 检查路径权限与格式
Windows环境下路径问题常导致文件创建失败:
- 确保项目路径不含中文、空格或特殊符号,改用纯英文路径
- 右键终端选择「以管理员身份运行」,再执行创建命令
3. 手动补全文件并初始化
如果创建中断后已有部分文件,手动补全关键文件后继续:
- 在项目根目录创建
tsconfig.json,内容如下:
{ "compilerOptions": { "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true, "plugins": [{"name": "next"}], "paths": {"@/*": ["./*"]} }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"] }
- 创建
package.json,内容参考:
{ "name": "my-app", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@types/node": "20.8.0", "@types/react": "18.2.24", "@types/react-dom": "18.2.8", "autoprefixer": "10.4.16", "eslint": "8.51.0", "eslint-config-next": "13.5.6", "next": "13.5.6", "postcss": "8.4.31", "react": "18.2.0", "react-dom": "18.2.0", "tailwindcss": "3.3.3", "typescript": "5.2.2" } }
- 执行
bun install安装依赖,再用bun dev测试项目是否正常运行
4. 清理Bun缓存
缓存损坏可能引发异常,清理后重新尝试创建:
bun pm cache rm
5. 临时用npm创建后切换Bun
如果以上方法无效,先用npm生成项目,再用Bun接管依赖与运行:
npx create-next-app my-app cd my-app bun install bun dev
内容的提问来源于stack exchange,提问作者Jayman
相关产品推荐
相关产品推荐

