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.

Unable to bundle individual packages (node_modules missing)

See original GitHub issue

Hi, I have some problems to be able to produce working individual packages. I don’t have node_modules in the .zip files

Here is an extract of my serverless conf serverless.yml

plugins:
  - serverless-esbuild
  - serverless-offline-local-authorizers-plugin
  - serverless-offline
  - serverless-stack-output
  - serverless-prune-plugin

custom:
  esbuild:
    bundle: true
    minify: false
    sourcemap: true
    packager: npm
    installExtraArgs: ['--production']
    exclude: ['aws-sdk', 'pg-native']
    plugins: plugins.js
    keepOutputDirectory: true

package:
  patterns:
    - '!node_modules/.prisma/client/query-engine-*'
    - '!node_modules/prisma/query-engine-*'
    - '!node_modules/@prisma/engines/**'
    - 'node_modules/.prisma/client/query-engine-rhel-*'
  individually: true

plugin.js

const { nodeExternalsPlugin } = require('esbuild-node-externals');

module.exports = [nodeExternalsPlugin()];

In the .esbuild/.build/ I have the node_modules with all the dependencies and I can see in the output of serverless deploy the Packing external modules: completed also with all my dependencies present in the package.json When I go to .esbuild/.serverless in one of my individual .zip I can see that I only have the dep indicated in the pattern (i.e: .prisma/client…) and a .js with a js.map files with my function code. If I remove the patterns conf, there only the function code.

When I trigger the functions, I have error complaining about missing modules. The functions works when there is individual: false

Versions (please complete the following information):

  • OS: Mac os M1
  • serverless: 3.19.0
  • esbuild: 0.14.43
  • serverless-esbuild: 1.30.0
  • esbuild-node-externals: 1.4.1

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
webdevericcommented, Jul 18, 2022

I’m having the same issue with node_modules missing in the zip artifact.

In my case, I’m using format: 'esm' and platform: 'node'. I’ve debugged this and found the issue (for me) is in getDepsFromBundle().

I think this function should take into account the output format, not the platform.

https://github.com/floydspace/serverless-esbuild/blob/a233a1a5294ddf0875341312590f0078f468ae26/src/helper.ts#L125-L132

0reactions
clementACcommented, Sep 27, 2022

Sorry for not answering. I eventually not use individually:true for the past months. I’m now trying to make it work again. On node 14 everything seems to work as expected but as soon as I update to node 16, the behavior is not the same. Patterns seems broken =/

I have this in every function where I want prisma integrated:

 package:
   patterns:
      - '!node_modules/.prisma/**'
      - '!node_modules/prisma/libquery_engine-*'
      - '!node_modules/@prisma/engines/**'
      - 'node_modules/.prisma/client/libquery_engine-rhel-*'
      - 'node_modules/.prisma/client/*.js'

The directives are respected concerning the .prisma and prisma directory but for the @prisma directory nothing is taken into account and I have artifact that bloat my final packages.

The @prisma directory is directly linked to the package whereas the two others are generated maybe it’s a kind of a race condition?

As it seems not fully related, I made another issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modules missing from node_modules but listed in lock file
My build scripts started failing after a recent yarn install and I noticed that certain packages were completely missing from the ...
Read more >
npm install is missing modules - node.js - Stack Overflow
This just goes through package.json in each dependency. I need to install dependencies, which are used in project, but somehow forgotten to ...
Read more >
Getting Started - ESBuild
First, install the react and react-dom packages: npm install react react-dom ... node_modules/.bin/esbuild app.jsx --bundle --outfile=out.js
Read more >
package.json - npm Docs
In cases where you need to preserve npm packages locally or have them available through a single file download, you can bundle the...
Read more >
Migration | Yarn - Package Manager
This guide will let you migrate without losing your node_modules folder. ... For this reason, we prefer to list it here as a...
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