1

I want to build my NextJS application which coded in typescript. In my local computer it is working fine. I can just call next build and it works fine. In my hosting server, it gives me this error:

> 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).

I have tried to install typescript with: npm install --save-dev typescript also npm -g typescript but it is still giving me the same error.

Here is my 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"
  }
...

Both server and my local computer are using Node 16.15.1. The server is using pm2 to run the script (I tried to run it manually from SSH, but this error is there).

I do not know what causes this because typescript is installed. Please help someone?

1 Answer 1

1

The issue is that typescript is installed as a dev dependency, which wouldn't be installed in a production environment.

Inside of your package.json, move "typescript": "4.6.4", from devDependencies --> dependencies.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.