question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The serverless-esbuild bundler fails with Typeorm/Prisma

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mishabrumlcommented, Jun 15, 2022

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
1reaction
samchungycommented, May 6, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Esbuild - Serverless Framework: Plugins
Serverless plugin for zero-config JavaScript and TypeScript code bundling using promising fast & furious esbuild bundler and minifier.
Read more >
Typeorm doesn't work with Serverless Framework AWS ...
Looks like you're using esbuild to bundle your lambdas? Some node modules don't like being bundled with esbuild and you have to add...
Read more >
Deploying to AWS Lambda - Prisma
In this guide, you will set up and deploy a serverless Node.js REST API to AWS Lambda using the Serverless Framework. AWS Lambda...
Read more >
Typeorm doesn't work with Serverless Framework AWS Lambda
Looks like you're using esbuild to bundle your lambdas? Some node modules don't like being bundled with esbuild and you have to add...
Read more >
floydspace/serverless-esbuild (Raised $0.00) - Issuehunt
A Serverless framework plugin to bundle JavaScript and TypeScript with extremely fast esbuild ... The serverless-esbuild bundler fails with Typeorm/Prisma.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found