0

I have an Nx project that has a backend module that I'd like to deploy. My problem is that after compilation the node_modules folder becomes huge and Heroku rejects my deployment.

I tried deleting the node_modules folder because I thought that after compiling the project I'm not gonna need it anymore.

What happened after I ran node main.js was this:

Error: Cannot find module 'tslib'
Require stack:
- /dist/apps/backend/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.752 (/dist/apps/backend/main.js:2:898496)
    at __webpack_require__ (/dist/apps/backend/main.js:2:898874)
    at /dist/apps/backend/main.js:2:899067
    at /dist/apps/backend/main.js:2:899812
    at Object.<anonymous> (/dist/apps/backend/main.js:2:900044)
    at Module._compile (node:internal/modules/cjs/loader:1105:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/dist/apps/backend/main.js' ]

As it turns out this main.js that I've compiled (with Webpack) still needs some external dependencies.

How can I configure a compilation that does not need node_modules?

Adam Arold
  • 29,285
  • 22
  • 112
  • 207

1 Answers1

0

You can't run your project without the node_modules. When you run your app, you need to have the node_modules at the root path and your dist folder. It should look like this :

- dist
- node_modules
Chalom.E
  • 617
  • 5
  • 20