Error: Cannot find module 'strapi' when trying to build production

hi, i want to deloy the backend to heroku but when i try to run the command

NODE_ENV=production npm start

this error show up:

> my-project@0.0.0 start /Users/tanhuynh/dev/getex
> node server.js

  throw err;

Error: Cannot find module 'strapi'
Require stack:
- /Users/tanhuynh/dev/getex/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/tanhuynh/dev/getex/server.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  requireStack: [ '/Users/tanhuynh/dev/getex/server.js' ]
npm ERR! errno 1
npm ERR! my-project@0.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-project@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tanhuynh/.npm/_logs/2021-06-08T05_36_22_060Z-debug.log

can anyone explain to me why? Thank you

Hi @tanhuynh, just to find out more about what you tried, did you run npm install before running in production?

Oh, i’m an idiot when i trying to run this command outside of backend directory . LOL. Please close this question. Thank you

I do have the same problem, and probably I’m idiot but is not working for me

what do you mean backend directory? root directory for my project?

I mean you need to run this command inside your root directory (Backend directory)