0

I've just started to use Mac iOS and when I started to set up a new backend (TypeScript) project I faced the problem that all the packages in npm scripts do not work.

Cannot find module 'typescript/bin/tsc'
Require stack:
- /Users/valera/Documents/projects/web/bwtc-backend/node_modules/tsc-watch/lib/tsc-watch.js
- /Users/valera/Documents/projects/web/bwtc-backend/node_modules/tsc-watch/index.js

I checked my node_modules folder and even deleted it and npm i packages again but it did not help. For some reason, it cannot see them or something.

My package.json file:

{
  "name": "name",
  "main": "server.js",
  "private": true,
  "scripts": {
    "clean": "rm -rf ./dist",
    "tsc": "tsc",
    "start:build": "npm-run-all clean tsc",
    "start:dev": "cross-env NODE_ENV=DEVELOPMENT tsc-watch --onSuccess 'node ./dist/server.js'",
    "dev": "npm-run-all clean start:dev",
    "prod": "npm-run-all clean start:build"
  },
  "license": "ISC",
  "dependencies": {
    "dotenv": "^8.2.0",
    "express": "4.17.1",
    "telegraf": "^4.0.0"
  },
  "devDependencies": {
    "@types/express": "4.17.11",
    "cross-env": "^7.0.3",
    "npm-run-all": "^4.1.5",
    "tsc-watch": "^4.2.9"
  }
}

Nothing special. Everything worked fine on my Windows machine. Maybe there is some special way to use it on Mac, I don't know.

The only workaround I found is to use the packages I need to use in the script npm run dev for instance, as globally installed and not as a script in the package.json but run the whole script in a terminal (of course with the packages previously installed globally).

I believe it shouldn't be this way.

Can anyone help me out here or has any ideas on the issue?

  • 1
    To be honest, I don't know the reason or I would fix it on my system as well - just have't spent the time to look into it. However, if you own the `package.json` you can invoke local tools and ensure it is from the proper `node_nodules` by running it with `npx`. For example: `npx tsc` will work. Another comment, instead of `rm -rf ./dist` use `rimraf` which is portable, e.g. `rimraf ./dist`. – Mike Coakley Feb 26 '21 at 00:27
  • 1
    check this answer https://stackoverflow.com/a/54541104/7237884 – Panagiotis Bougioukos Feb 26 '21 at 00:29
  • @MikeCoakley nothing works with npx. I have no idea what's the issue here. Maybe a PATH variable or something but I never had this kind of issue before. And thanks, I agree rimraf is good –  Feb 26 '21 at 10:22
  • @Boug, Thanks! I'll check it out –  Feb 26 '21 at 10:23

1 Answers1

0

The only way to solve it was to COMPLETELY uninstall node and npm. I uninstalled it wherever I could to check is I don't have any versions there like brew or nvm and deleted all the files of node and npm from my machine.

Then I've downloaded the latest version of node from the official website and after that updated npm to the latest version too.

After that, it worked for me