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.

esbuild minify unexpect transform

See original GitHub issue

Describe the bug

when I use config for vite

export default {
build: {
    target: 'chrome60'
  }
}

esbuild transform dynamic import to require.

like this:

import('./workerImport-a2c311d3.js')

to

require('./workerImport-a2c311d3.js')

may be chrome63 support dynamic import. chrome60 no support. But I don’t think this conversion meets the expectations.

I think need to polyfill import in chrome63

Reproduction

https://stackblitz.com/edit/node-qfc2yz?devtoolsheight=33&file=index.js

System Info

any

Used Package Manager

pnpm

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bluwycommented, Jul 14, 2022

Yeah I think the error would be more obvious if we preserve it. And this also helps to make sure that the modern bundle can be used by modern browsers too. If we downlevel to require it’ll break even on chrome100.

I tried to auto issue a warning too but I’m not sure if there’s a neat way of doing so with esbuild.

1reaction
sapphi-redcommented, Jul 10, 2022

I think import needs to be preserved by esbuild, but it needs renamed in the final output. import is a keyword in js and to polyfill dynamic import, it needs to be a different name. https://github.com/GoogleChromeLabs/dynamic-import-polyfill#:~:text=The name of the dynamic import polyfill function added to the global scope.

Note that renderDynamicImport/dynamicImportFunction cannot be used because Vite uses import in renderChunk by build-import-analysis which runs after them (#8588).

Read more comments on GitHub >

github_iconTop Results From Across the Web

minify unexpect transform #2089 - evanw/esbuild - GitHub
Describe the bug run for this config // run `node index.js` in the terminal const esbuild = require('esbuild'); const code = ` const...
Read more >
API - ESBuild
The transform API can take the following options: Simple options: Define; Format; Loader; Minify; Platform; Sourcemap; Target. Advanced options:.
Read more >
Introduction to esbuild - Telerik
Let's see how we can increase performance using a modern and extremely fast JavaScript bundler: esbuild.
Read more >
Newest 'esbuild' Questions - Stack Overflow
I need a function or API which convert React Js code into plain Js code ... My esbuild build script is supposed to...
Read more >
Shared Options | Vite
minifyWhitespace options to false . Note the esbuild.minify option can't be used to override build.minify . Set to false to disable esbuild transforms....
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