esbuild-loader icon indicating copy to clipboard operation
esbuild-loader copied to clipboard

cannot support webpack require.ensure

Open swk777 opened this issue 3 years ago • 6 comments

Bug description

截屏2021-08-23 22 45 09

succeed to build but fail to open the page

Reproduction

just use require.ensure to support dynamic import

Node.js package manager

yarn

Environment

esbuild-loader version: 2.15.1
Webpack version: 4.36.0
Operating System: macOS 10.15.7
Node version: 16.2.0
Package manager (yarn) and version: yarn 1.23.0

Can you contribute a fix?

  • [ ] I’m interested in opening a pull request for this issue.

swk777 avatar Aug 23 '21 14:08 swk777

I will look into this but FYI require.ensure() has been superseded by import() so this is low priority.

privatenumber avatar Aug 23 '21 18:08 privatenumber

I will look into this but FYI require.ensure() has been superseded by import() so this is low priority.

thx 👍

swk777 avatar Aug 23 '21 23:08 swk777

I'm still getting this issue when using await import(...) I assume it's related?

freshollie avatar Nov 06 '21 12:11 freshollie

This seems to be related to https://esbuild.github.io/api/#splitting

Without code splitting enabled, an import() expression becomes Promise.resolve().then(() => require()) instead. This still preserves the asynchronous semantics of the expression but it means the imported code is included in the same bundle instead of being split off into a separate file.

I would assume the transform function is doing this.

freshollie avatar Nov 06 '21 14:11 freshollie

I don't think so. It only has "Supported by: Build" underneath. The features in the transform function has "Supported by: Transform".

Supporting require.ensure() is low priority, but import() is very high priority. If you think there's a bug, please open a new issue with a minimal reproduction.

privatenumber avatar Nov 06 '21 20:11 privatenumber

Yeah, I've checked this and transform is definitely leaving the await imports intact. Seems to be a webpack problem but nothing to do with this plugin :)

freshollie avatar Nov 07 '21 11:11 freshollie

Decided not to support require.ensure since it's deprecated in favor of import()

privatenumber avatar Dec 01 '22 13:12 privatenumber