Cannot find module "express"


#1
module.js:550

throw err;

^


Error: Cannot find module 'express'

at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/app/server.js:5:16)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)

I’m getting this error since two days and without the server.js the bot is working properly. Any ideas how to fix it?


#2

Hey @BullDogBg, this often means that there’s a problem somewhere in your package.json or dependencies that disrupts the pnpm install process. Express never actually gets installed, and it’s the first package that’s required in your code path, so Node throws an error when trying to find it - in other words it has nothingh to do with Express directly; that’s just the first problem your project encounters.

Running pnpm-install or its close mat enable-pnpm in your project’s console (see https://support-assets.glitch.me/logs-pane-console for how to get there if you don’t know how) and watching the output can often show you the actual source of the problem. If you want to share your project name someone can take a closer look.


Express missing ... Again. Help!
#3

Hey @cori, can you take a look because I’ve lost the thread? I’ll DM you an link if you want.


#4

Sure. I just need the project name (some Glitch staff can view private projects when requested to).


#5

Thank you, It’s the-clashers-bot.


#6

Hey @BullDogBg I was able to resolve the issue in a remix of your project by running enable-pnpm in the console. This forces a full reinstall of all the modules. Have you tried that yet?


#7

No, but I’ll try. Thank you very much!


#8

Yes everything is OK now. Thank you again!


#9

@cori 2 weeks later same problem, but with the better-sqlite3 module. I’ve tried enable-pnpm, refresh and reinstalling the module but nothing helped. Without the const requiring it works.


#10

Hey @BullDogBg I think this problem might be related to the fact that you have node called out in your dependencies. I’d suggest trying removing that dependency and then running enable-pnpm again to see if that clears things up. You don’t need to declare node as a dependency, and sometimes doing so results in (p)npm trying to resolve other dependencies inside the node folder created in the pnpm volume instead of in the right spot.

If you need a specific version of node, the correct spot to place that is in the engines section just below your dependencies.