serverless-esbuild: The serverless-esbuild bundler fails with Typeorm/Prisma

Describe the bug When trying to create a aws lambda with typescript and try to use some ORM like Typeorm and Prisma, whenever I write serverless deploy or serverless-offline, I get the same exact error.

To Reproduce Clone this repo: https://github.com/joaocasarin/aws-lambda-typeorm-error Run yarn install to install dependencies and then either serverless deploy or serverless offline. You will get the same exact error as in the below screenshot.

PS.: You will see the typeorm version in the branch main, and the prisma version in the branch prisma. Both executes as the description.

Expected behavior The lambda should execute as normal: create the lambda function, expect some input from user in a POST request body, and response with the created user.

Screenshots or Logs image

Versions (please complete the following information):

  • OS: Windows 10
  • Serverless Framework Version: 3.14.0
  • Serverless Plugin Version: 6.2.1
  • serverless-esbuild version: ^1.26.2

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 22 (5 by maintainers)

Most upvoted comments

I’m also having this issue, trying to use Typeorm with esbuild 😢

Project compiles fine, until I import something from Typeorm into a handler.

I’ve got typeorm, pg and pg-native as externals

The sls:package results in a weird crash loop


> sls:package
> rm -rf .esbuild && sls package "-s" "nonprod"

Error:
RangeError: Maximum call stack size exceeded
    at Array.values (<anonymous>)
    at /Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:75:38
    at Array.forEach (<anonymous>)
    at recursiveFind (/Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:75:30)
    at /Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:83:17
    at Array.forEach (<anonymous>)
    at recursiveFind (/Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:75:30)
    at /Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:83:17
    at Array.forEach (<anonymous>)
    at recursiveFind (/Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:75:30)
    at /Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:83:17
    at Array.forEach (<anonymous>)

    ....etc...

    at recursiveFind (/Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:75:30)
    at flatDep (/Users/mishabruml/*****/node_modules/serverless-esbuild/dist/helper.js:92:5)
    at /Users/mishabruml/*****/node_modules/serverless-esbuild/dist/pack.js:140:49
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0)
    at async EsbuildServerlessPlugin.pack (/Users/mishabruml/*****/node_modules/serverless-esbuild/dist/pack.js:129:5)
    at async before:package:createDeploymentArtifacts (/Users/mishabruml/*****/node_modules/serverless-esbuild/dist/index.js:83:17)
    at async PluginManager.runHooks (/Users/mishabruml/*****/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/Users/mishabruml/*****/node_modules/serverless/lib/classes/plugin-manager.js:563:9)
    at async PluginManager.run (/Users/mishabruml/*****/node_modules/serverless/lib/classes/plugin-manager.js:604:7)
    at async Serverless.run (/Users/mishabruml/*****/node_modules/serverless/lib/serverless.js:174:5)
    at async /Users/mishabruml/*****/node_modules/serverless/scripts/serverless.js:687:9

Can you try downgrading to serverless-offline 8.5.0. I’m fairly certain it’s related to it. I’m moving house right now so I don’t have alot of time.

indeed the error changes to another… Sorry for bothering I actually hadn’t tried to downgrade before. I’ll be commenting on that discussion about my case, because there is still another error.

Had a quick look. You might need to declare bcrypt as external too unfortunately

Yeah! After adding bcrypt to external libs it worked… But why was that even necessary? I mean, there is no log saying to do something like that and I’m also using some others external libs such as yup and uuid, why wasn’t them necessary to be added in the external entry?

because that library is written in a way where it’s expecting package.json to be at a specific spot in your directory.