NextJS:未安装下一个生成Typescript



我想构建用typescript编码的NextJS应用程序。在我的本地电脑中,它运行得很好。我可以直接打给next build,它工作得很好。在我的托管服务器中,它给了我这个错误:

> next build
It looks like you're trying to use TypeScript but do not have the required package(s) installed.
Please install typescript by running:
npm install --save-dev typescript
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your pages directory).

我试着用:npm install --save-dev typescriptnpm -g typescript安装typescript,但它仍然给我同样的错误。

这是我的package.json:

...
"scripts": {
"dev": "set NODE_ENV=development && next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"generateDBModel": "prisma generate",
"migrateDB": "prisma migrate dev",
"syncDB": "npm run generateDBModel && npm run migrateDB",
"generate-capacitor-config": "node ./generate_capacitor_config.js",
"build-mobile": "set NODE_ENV=production && npm run generate-capacitor-config && next build && next export && npx cap sync && npx cap open android",
"android": "set NODE_ENV=development && npm run generate-capacitor-config && npx cap sync && npx cap open android && npm run dev"
},
"dependencies": {
"@capacitor/android": "^3.5.1",
"@capacitor/app": "1.1.1",
"@capacitor/core": "3.5.1",
"@capacitor/haptics": "1.1.4",
"@capacitor/keyboard": "1.2.2",
"@capacitor/status-bar": "1.0.8",
"@prisma/client": "^3.14.0",
"@types/axios": "^0.14.0",
"@types/crypto-js": "^4.1.1",
"@types/ftp": "^0.3.33",
"@types/highlight.js": "^10.1.0",
"@types/nodemailer": "^6.4.4",
"@types/react-color": "^3.0.6",
"@types/react-google-recaptcha": "^2.1.5",
"@uiw/react-md-editor": "^3.6.0",
"axios": "^0.27.2",
"crypto-js": "^4.1.1",
"ftp": "^0.3.10",
"highlight.js": "^11.5.1",
"ip": "^1.1.8",
"next": "12.1.6",
"next-remove-imports": "^1.0.6",
"node-html-parser": "^5.3.3",
"nodemailer": "^6.7.5",
"react": "18.1.0",
"react-color": "^2.19.3",
"react-dom": "18.1.0",
"react-google-recaptcha": "^2.1.0",
"react-icons": "^4.3.1",
"react-markdown": "^8.0.3",
"sass": "^1.51.0"
},
"devDependencies": {
"@capacitor/cli": "3.5.1",
"@types/node": "17.0.34",
"@types/react": "18.0.9",
"@types/react-dom": "18.0.4",
"eslint": "8.15.0",
"eslint-config-next": "12.1.6",
"prisma": "^3.14.0",
"typescript": "4.6.4",
"webpack-cli": "^4.10.0"
}
...

服务器和我的本地计算机都在使用Node 16.15.1。服务器正在使用pm2来运行脚本(我试图从SSH手动运行它,但存在此错误(。

我不知道是什么原因造成的,因为安装了typescript。请帮帮别人?

问题是typescript是作为开发依赖项安装的,它不会安装在生产环境中。

在您的package.json中,从devDependencies中移动"typescript": "4.6.4",-->依赖关系。

相关内容

最新更新