Comments (25)
For anyone new to esbuild and finding this page, @ffxsam's code works but you need to specify write: false
in the options for args.outputFiles
to be present.
# serverless.yml
custom:
esbuild:
plugins: plugins.js # file that contains the sourcemap-upload code
sourcemap: external # using 'external' here as we only need the map files
write: false
from serverless-esbuild.
@amitUpscale
I did, and it seems to have worked well for now.
For esbuild-serverless configuration, we have:
esbuild:
bundle: true
minify: false
sourcemap: external # we had to set this to external
sourcesContent: true
exclude: ['aws-sdk']
target: 'node18'
platform: 'node'
plugins: esbuildPlugins.js # we declare an external plugin
And for the plugin file, we have:
const { sentryEsbuildPlugin } = require('@sentry/esbuild-plugin')
module.exports = [
sentryEsbuildPlugin({
org: 'my-org',
project: 'the-sentry-project',
authToken: process.env.SENTRY_AUTH_TOKEN,
release: {
name: process.env.APP_VERSION, // would be your release version
finalize: process.env.SENTRY_RELEASE_FINALIZE === 'true', // we have CI for beta and prod. We only finalize on prod.
dist: 'server',
},
}),
]
With that, just by running the serverless deploy command, sentry will take care of uploading the source files. We did it remix, and this is the way for us to send the server side source-maps.
from serverless-esbuild.
I've been working on it, and making good progress. So far, this will save out source maps to their own folder. The last part is to just have this execute sentry-cli
to upload them.
const fs = require('fs');
const path = require('path');
const envPlugin = {
name: 'upload-sourcemaps',
setup(build) {
build.onEnd(args => {
for (const file of args.outputFiles) {
const { base, dir } = path.parse(file.path);
if (/\.map$/.test(file.path)) {
const funcDir = dir.replace(/.*\.build\//, '')
fs.mkdirSync(`./.sourcemaps/${funcDir}`, { recursive: true });
fs.writeFileSync(`./.sourcemaps/${funcDir}/${base}`, file.contents);
continue;
}
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(file.path, file.contents);
}
});
},
};
module.exports = [envPlugin];
from serverless-esbuild.
Or you could leave the source map where they are and feed the path to sentry cli. In any case, you should open a repo. I am sure many teams would be happy to have such a plugin for esbuild (in a serverless-esbuild project or other). Should we close this issue as it is not specifically linked to serverless-esbuild ?
from serverless-esbuild.
When combining this solution with typescript, has anybody experienced your stack trace referring to the minified/bundled .js
file instead of its .ts
file?
from serverless-esbuild.
Maybe more of a esbuild plugin to build ?
from serverless-esbuild.
Sure!
from serverless-esbuild.
The esbuild plugin automatically creates releases and upload source maps when bundling the app, but serverless-esbuild bundles in response to multiple serverless lifecycle hooks (e.g. package, deploy, invoke local, offline, etc.) While appropriate for package and deploy, I don't think we want the plugin creating releases and uploading source maps when invoking a function locally or running offline.
To be useful in the context of serverless-esbuild, I think we need a way to conditionally use the plugin based on serverless lifecycle hooks.
from serverless-esbuild.
Following @rafael-lua's comment 🙌🏻 I also managed to upload sourcemaps and remove them from the zip by specifying them in the sourcemaps.filesToDeleteAfterUpload
option, e.g.
const { sentryEsbuildPlugin } = require('@sentry/esbuild-plugin')
module.exports = [
sentryEsbuildPlugin({
org: 'my-org',
project: 'the-sentry-project',
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: {
assets: ['./.esbuild/.build/**/*'],
filesToDeleteAfterUpload: ['./.esbuild/.build/**/*.js.map']
}
})
]
from serverless-esbuild.
@olup I was just looking into this, but since plugins are experimental, I couldn't find any documentation.
I looked through the source code a bit, and I didn't see any way for a plugin to see which files were saved as a result of the build process.
Correction: looks like if I set the write
option to false
, then my plugin gets a full array of files with their contents as Uint8Array
objects. So, I'm thinking I might be able to filter this list and save the .map
files in a separate folder, then spawn a sentry-cli
process to upload the source maps. This could work!
Now I just need to figure out where to save the .js
files so Serverless can find them & deploy them to AWS, and how/where to save the .map
files.
from serverless-esbuild.
Thing is, packaging the js file is a bit involved and is partly the reason this lib exists. The code has been refined to cover many edge case. I wonder if there is a way to have an esbuild plugin that can work alongside normal operations of this lib.
from serverless-esbuild.
Maybe something around https://esbuild.github.io/plugins/#resolve-callbacks ? There is quite a bit of doc to fiddle around.
from serverless-esbuild.
Leaving the source maps where they're placed by esbuild would include them in the ZIP file that goes up to AWS, and that's not necessary.
I'll absolutely create a public repo for this once it's done!
from serverless-esbuild.
Hi there, can we close this as it will be handles by some esbuild plugin ?
from serverless-esbuild.
I'm converting a webpack build over to ESBuild and I've come across this exact requirement; does anyone know if a plugin has been released to handle this?
from serverless-esbuild.
hi @Steakeye, I don't this the plugin exists as npm package, you can try using the code snipped suggested by @ffxsam
from serverless-esbuild.
@ffxsam did you ever make a public plugin for this? this is still the top google search result for this issue so I think it would be helpful if there was a final resolution here.
from serverless-esbuild.
@kopertop I didn't post it officially anywhere, no. I've since moved to Serverless Stack, so I had to modify my plugin code a bit.
from serverless-esbuild.
@henriquecarv Yes. Did you ever figure this out?
from serverless-esbuild.
@atwoodjw I did not figure it out back then, so I stopped trying after a while. Might get back to it again sometime later :)
from serverless-esbuild.
Sentry now provides an esbuild plugin for uploading source maps: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/esbuild.
from serverless-esbuild.
@epiphone thank you for this, I will give it a go
from serverless-esbuild.
@walterholohan if you get it to work with serverless I'd be very interested in your config 😅
Merry xmas everyone 🎁🎄
from serverless-esbuild.
Hopefully @epiphone can provide his magic sauce on how he got it working
from serverless-esbuild.
did anyone try out using Sentry with serverless-esbuild and sentry esbuild plugin
from serverless-esbuild.
Related Issues (20)
- Bun support HOT 1
- Unable to serverless package when no lambdas exist HOT 3
- serverless deploy fails without a reason when using esbuild-plugin-tsc HOT 2
- Rewrite Module Packaging Logic HOT 3
- I'm not sure if it supports layers
- pnpm: external modules bundled without their nested modules. HOT 2
- Indirect dependency marked as external missing in package HOT 1
- Slow performance when using external property
- Esbuild cannot rebuild error
- `patterns` not respected at `invoke local`
- sls package fails with individually: true for specific function Error: ENOENT: no such file or directory, copyfile
- update esbuild peerDependency HOT 1
- Support ESBuild 0.20.0 HOT 2
- watch function work with serverless-localstack.
- Possible memory-use regression in v1.48.1 HOT 1
- Stuck on Need a faster logging experience when using serverless-stack with serverless-esbuild HOT 1
- Support Lambda custom runtimes HOT 2
- Trouble importing to esbuild.config.js from an internal monorepo package HOT 1
- Hangs indefinitely on esbuild error HOT 1
- Overriding the keyword used to get the handler in the lambda function defintion HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-esbuild.