Home > Software engineering >  Why Heroku don't find moment?
Why Heroku don't find moment?

Time:03-28

i am creating a discord bot and hosting it on heroku. i installed the moment.js library but it can't find it giving the following error

2022-03-27T12:41:48.954612 00:00 app[worker.1]: Error: Cannot find module 'moment'
2022-03-27T12:41:48.954612 00:00 app[worker.1]: Require stack:
2022-03-27T12:41:48.954612 00:00 app[worker.1]: - /app/bot.js
2022-03-27T12:41:48.954622 00:00 app[worker.1]:     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-27T12:41:48.954625 00:00 app[worker.1]:     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-27T12:41:48.954625 00:00 app[worker.1]:     at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-27T12:41:48.954626 00:00 app[worker.1]:     at require (node:internal/modules/cjs/helpers:102:18)
2022-03-27T12:41:48.954626 00:00 app[worker.1]:     at Object.<anonymous> (/app/bot.js:3:16)
2022-03-27T12:41:48.954626 00:00 app[worker.1]:     at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-27T12:41:48.954626 00:00 app[worker.1]:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
2022-03-27T12:41:48.954627 00:00 app[worker.1]:     at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-27T12:41:48.954627 00:00 app[worker.1]:     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-27T12:41:48.954627 00:00 app[worker.1]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
2022-03-27T12:41:48.954628 00:00 app[worker.1]:   code: 'MODULE_NOT_FOUND',
2022-03-27T12:41:48.954628 00:00 app[worker.1]:   requireStack: [ '/app/bot.js' ]
2022-03-27T12:41:48.954628 00:00 app[worker.1]: }

my code

const moment = require('moment');

how should i do?

package.json:

{
  "name": "freaksland-bot",
  "version": "1.0.0",
  "description": "",
  "main": "bot.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@discordjs/voice": "^0.8.0",
    "moment.js": "^2.29.1",
    "discord.js": "^13.6.0",
    "init": "^0.1.2"
  }
}

CodePudding user response:

You are depending on moment.js, but the correct package is just moment.

Did you manually add that to your package.json? First, remove that line.

Then add the correct package:

  • If you are using Yarn, run yarn add moment
  • If you are using NPM, run npm install moment

This should install the dependency locally and also add it to your package.json and the relevant lock file. Commit the changes to those files and redeploy.

CodePudding user response:

You should place the node_modules folder in your root directory

  • Related