Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate module wrapper functions in debug builds #1244

Merged
merged 1 commit into from
May 3, 2021
Merged

Conversation

evanw
Copy link
Owner

@evanw evanw commented May 3, 2021

Sometimes esbuild needs to wrap certain modules in a function when bundling. This is done both for lazy evaluation and for CommonJS modules that use a top-level return statement. Previously these functions were all anonymous, so stack traces for errors thrown during initialization looked like this:

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
    at getElectronPath (out.js:16:13)
    at out.js:19:21
    at out.js:1:45
    at out.js:24:3
    at out.js:1:45
    at out.js:29:3
    at out.js:1:45
    at Object.<anonymous> (out.js:33:1)

This release adds names to these anonymous functions when minification is disabled. The above stack trace now looks like this:

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
    at getElectronPath (out.js:19:15)
    at node_modules/electron/index.js (out.js:22:23)
    at __require (out.js:2:44)
    at src/base/window.js (out.js:29:5)
    at __require (out.js:2:44)
    at src/base/kiosk.js (out.js:36:5)
    at __require (out.js:2:44)
    at Object.<anonymous> (out.js:41:1)

This is similar to Webpack's development-mode behavior:

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
    at getElectronPath (out.js:23:11)
    at Object../node_modules/electron/index.js (out.js:27:18)
    at __webpack_require__ (out.js:96:41)
    at Object../src/base/window.js (out.js:49:1)
    at __webpack_require__ (out.js:96:41)
    at Object../src/base/kiosk.js (out.js:38:1)
    at __webpack_require__ (out.js:96:41)
    at out.js:109:1
    at out.js:111:3
    at Object.<anonymous> (out.js:113:12)

These descriptive function names will additionally be available when using a profiler such as the one included in the "Performance" tab in Chrome Developer Tools. Previously all functions were named (anonymous) which made it difficult to investigate performance issues during bundle initialization.

Closes #1236

@evanw evanw merged commit 7d25497 into master May 3, 2021
@evanw evanw deleted the issues/1236 branch May 3, 2021 22:59
Repository owner deleted a comment May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant