serverless-bundle icon indicating copy to clipboard operation
serverless-bundle copied to clipboard

Cannot deploy with nestjs (but sls offline works)

Open softmarshmallow opened this issue 5 years ago • 6 comments

ERROR in /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-application.js
Module not found: Error: Can't resolve '@nestjs/microservices' in '/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core'
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-application.js 112:115-147
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/index.js
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/g11n-service/src/lambda.ts

ERROR in /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-factory.js
Module not found: Error: Can't resolve '@nestjs/microservices' in '/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core'
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-factory.js 49:115-147
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/index.js
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/g11n-service/src/lambda.ts

ERROR in /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-application.js
Module not found: Error: Can't resolve '@nestjs/microservices/microservices-module' in '/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core'
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-application.js 17:120-173
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/index.js
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/g11n-service/src/lambda.ts

ERROR in /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-application.js
Module not found: Error: Can't resolve '@nestjs/websockets/socket-module' in '/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core'
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/nest-application.js 16:102-145
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/core/index.js
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/g11n-service/src/lambda.ts

ERROR in /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/common/cache/cache.providers.js
Module not found: Error: Can't resolve 'cache-manager' in '/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/common/cache'
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/common/cache/cache.providers.js 16:103-127
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/common/cache/cache.module.js
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/common/cache/index.js
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/@nestjs/common/index.js
 @ /Users/softmarshmallow/Documents/Apps/bridged/services/g11n-service/src/lambda.ts
 
  Error --------------------------------------------------
 
  Error: Webpack compilation error, see above
      at /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/serverless-webpack/lib/compile.js:36:17
      at arrayEach (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/lodash/lodash.js:516:11)
      at Function.forEach (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/lodash/lodash.js:9368:14)
      at /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/serverless-webpack/lib/compile.js:29:9
      at finalCallback (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/MultiCompiler.js:254:12)
      at /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/MultiCompiler.js:277:6
      at done (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/neo-async/async.js:2931:13)
      at runCompilers (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/MultiCompiler.js:181:48)
      at /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/MultiCompiler.js:188:7
      at /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/MultiCompiler.js:270:7
      at finalCallback (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/Compiler.js:257:39)
      at /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/Compiler.js:273:13
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:22:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/tapable/lib/Hook.js:154:20)
      at onCompiled (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/Compiler.js:271:21)
      at /Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/webpack/lib/Compiler.js:681:15
      at eval (eval at create (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
  From previous event:
      at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:521:22)
      at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:541:17)
      at ServerlessPlugin.<anonymous> (/Users/softmarshmallow/Documents/Apps/bridged/services/node_modules/serverless-webpack/index.js:94:53)
      at processImmediate (internal/timers.js:456:21)
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.18.3
     Framework Version:         2.15.0
     Plugin Version:            4.2.0
     SDK Version:               2.3.2
     Components Version:        3.4.3

softmarshmallow avatar Dec 12 '20 02:12 softmarshmallow

https://github.com/nestjs/nest/issues/1706

softmarshmallow avatar Dec 12 '20 02:12 softmarshmallow

    forceExclude:
      - '@nestjs/microservices'
      - '@nestjs/microservices/microservices-module'
      - '@nestjs/websockets/socket-module'
      - 'cache-manager'

this does the trick, but is this the right/ onlu solution?

softmarshmallow avatar Dec 12 '20 03:12 softmarshmallow

example production repository used by bridged.xyz https://github.com/bridgedxyz/services/blob/main/CONTRIBUTING.md

softmarshmallow avatar Dec 12 '20 03:12 softmarshmallow

    forceExclude:
      - '@nestjs/microservices'
      - '@nestjs/microservices/microservices-module'
      - '@nestjs/websockets/socket-module'
      - 'cache-manager'

this does the trick, but is this the right/ onlu solution?

This looks correct to me. Does the deployed cloud function perform as expected?

PenguinOfWar avatar Dec 18 '20 07:12 PenguinOfWar

Hi @softmarshmallow, looks like we meet again trying to bundle our @nestjs monorepo into a serverless function of reasonable size.

This seems to get me past my issues with nestjs. (I was having the same error). Still working on figuring out how to get prisma2 to bundle as well.

thebrianbug avatar Dec 16 '21 15:12 thebrianbug

I'm using this combination for production. I'll share the solution shortly when i get some freetime

softmarshmallow avatar Dec 21 '21 18:12 softmarshmallow