rdlabo-team/serverless-nestjs

Error when using `sls offline`

bensiu opened this issue · 2 comments

when I follow the documentation:

  • clone repo
  • npm install
  • npm start
    the application starts with no problems

when trying to use sls offline - I am having nice error:

[ 'Error: Cannot find module \'/Users/...my folder name.../dist/index\'', 'at Function.Module._resolveFilename (module.js:547:15)', 'at Function.Module._load (module.js:474:25)', 'at Module.require (module.js:596:17)', 'at require (internal/module.js:11:18)', 'at Object.createHandler (/Users/...my folder name.../node_modules/serverless-offline/src/functionHelper.js:192:17)', 'at handler (/Users/...my folder name.../node_modules/serverless-offline/src/index.js:624:40)', 'at Object.internals.handler (/Users/...my folder name.../node_modules/hapi/lib/handler.js:101:51)', 'at request._protect.run (/Users/...my folder name.../node_modules/hapi/lib/handler.js:32:23)', 'at module.exports.internals.Protect.internals.Protect.run (/Users/...my folder name.../node_modules/hapi/lib/protect.js:60:12)', 'at exports.execute (/Users/...my folder name.../node_modules/hapi/lib/handler.js:26:22)', 'at each (/Users/...my folder name.../node_modules/hapi/lib/request.js:401:16)', 'at iterate (/Users/...my folder name.../node_modules/items/lib/index.js:36:13)', 'at done (/Users/...my folder name.../node_modules/items/lib/index.js:28:25)', 'at internals.Auth.payload (/Users/...my folder name.../node_modules/hapi/lib/auth.js:235:16)', 'at each (/Users/...my folder name.../node_modules/hapi/lib/request.js:401:16)', 'at iterate (/Users/...my folder name.../node_modules/items/lib/index.js:36:13)', 'at done (/Users/...my folder name.../node_modules/items/lib/index.js:28:25)', 'at internals.payload (/Users/...my folder name.../node_modules/hapi/lib/route.js:328:16)', 'at each (/Users/...my folder name.../node_modules/hapi/lib/request.js:401:16)', 'at iterate (/Users/...my folder name.../node_modules/items/lib/index.js:36:13)', 'at done (/Users/...my folder name.../node_modules/items/lib/index.js:28:25)', 'at module.exports.internals.Auth.internals.Auth._authenticate (/Users/...my folder name.../node_modules/hapi/lib/auth.js:222:16)', 'at internals.Auth.authenticate (/Users/...my folder name.../node_modules/hapi/lib/auth.js:197:17)', 'at each (/Users/...my folder name.../node_modules/hapi/lib/request.js:401:16)', 'at iterate (/Users/...my folder name.../node_modules/items/lib/index.js:36:13)', 'at done (/Users/...my folder name.../node_modules/items/lib/index.js:28:25)', 'at internals.state (/Users/...my folder name.../node_modules/hapi/lib/route.js:292:16)', 'at each (/Users/...my folder name.../node_modules/hapi/lib/request.js:401:16)', 'at iterate (/Users/...my folder name.../node_modules/items/lib/index.js:36:13)', 'at Object.exports.serial (/Users/...my folder name.../node_modules/items/lib/index.js:39:9)', 'at internals.Request._lifecycle (/Users/...my folder name.../node_modules/hapi/lib/request.js:404:18)', 'at internals.Request._match (/Users/...my folder name.../node_modules/hapi/lib/request.js:381:17)', 'at internals.Request._execute (/Users/...my folder name.../node_modules/hapi/lib/request.js:335:21)', 'at Domain.request._protect.enter (/Users/...my folder name.../node_modules/hapi/lib/connection.js:275:25)', 'at Domain.run (domain.js:242:14)', 'at module.exports.internals.Protect.internals.Protect.enter (/Users/...my folder name.../node_modules/hapi/lib/protect.js:76:17)', 'at Server.<anonymous> (/Users/...my folder name.../node_modules/hapi/lib/connection.js:273:30)', 'at emitTwo (events.js:126:13)', 'at Server.emit (events.js:214:7)', 'at parserOnIncoming (_http_server.js:619:12)' ]

if building it before sls offline by using npm run prestart:prod - I am having a generic error:

[ExceptionHandler] Map#toJSON isn't generic +8ms TypeError: Map#toJSON isn't generic at String.toJSON (/usr/local/lib/node_modules/serverless/node_modules/core-js/modules/_collection-to-json.js:6:38) at Function.<anonymous> (/usr/local/lib/node_modules/serverless/node_modules/core-js/modules/_ctx.js:18:15) at JSON.stringify (<anonymous>) at Function.stringify [as default] (/Users/...my folder name.../node_modules/fast-safe-stringify/index.js:11:18) at ModuleTokenFactory.getDynamicMetadataToken (/Users/...my folder name.../node_modules/@nestjs/core/injector/module-token-factory.js:22:44) at ModuleTokenFactory.create (/Users/...my folder name.../node_modules/@nestjs/core/injector/module-token-factory.js:12:27) at ModuleCompiler.compile (/Users/...my folder name.../node_modules/@nestjs/core/injector/compiler.js:21:47) at <anonymous> at process._tickDomainCallback (internal/process/next_tick.js:228:7)

Can you advice what could be wrong?

Hey @bensiu I ran into the same issue and realised by reading through it that it is looking for a dist folder which only becomes available after also doing an:
npm run build
This should then allow you to sls offline and work as expected.