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.

Extra file (package.json) not included into final zips

See original GitHub issue

Describe the bug Extra files (package.json to be exact) are not included into the final zips.

Versions (please complete the following information):

  • OS: Mac
  • Serverless Framework Version: 3.18.2
  • Plugin Version: 1.30.0

Additional context So basically I wanted to use esbuild with ESM (AWS supports this for a while already). I set the type inside package.json to module and everything else needed for this move, worked fine, but the problem I stumbled upon is that serverless-esbuild simply does not include the package.json into the zip even if it’s added to the package.patterns like so below.

custom:
  esbuild:
    bundle: true
    minify: false
    packager: 'yarn'
    target: 'node16'
    keepOutputDirectory: true

package:
  individually: true
  excludeDevDependencies: true
  patterns:
    - 'package.json'

It looks like the .esbuild contains the the package.json, but the zips themselves don’t.

Of course I could just name my files .mjs instead, but that isn’t an ideal solution for me.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
floydspacecommented, Jun 1, 2022

@doteric yes, you’re absolutely right, only external modules, here is the thing, other dependencies are bundled and you don’t need them in generated package.json. so your assumption is correct, but could be vice versa, some of the params from base package.json would be copied to generated one, because you probably do not need scripts for instance nad other dev specific meta.

1reaction
floydspacecommented, May 30, 2022

hi @doteric , to be honest, not sure what is the reason we exclude, maybe because anyway we deliver bundled code and package.json used to be just unnecessary development artifacts, but feel free to test it locally with patch-package for instance and let as know, if you’d like raise a PR, keep in mind that we do not use root package.json for packaging dependencies, we generate one here https://github.com/floydspace/serverless-esbuild/blob/master/src/pack-externals.ts#L293, maybe it makes sense store this file, not the root one, but we’d also have to copy some necessary module meta located in root package.json you mentioned, so your js files are treated correctly by nodejs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How to automatically zip files with Node.js and npm
The files array is a whitelist of what to include. Here, it's just index.js and the lib directory. However, npm will also automatically...
Read more >
Serverless package does not include all modules when a ...
Description. When deploying multiple versions of a service or just versions of the function within the service, but sometimes some modules are ...
Read more >
Create an application source bundle - AWS Elastic Beanstalk
Create an application source bundle · Consist of a single ZIP file or WAR file (you can include multiple WAR files inside your...
Read more >
How To Work With Zip Files in Node.js - DigitalOcean
After you run the command, npm will install adm-zip and update the package.json file. Next, create a directory called test and move into...
Read more >
Common Configuration - electron-builder
in the package.json file of your project using the build key on the top level: ... If you want to use js file,...
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