[Bug] Used exports are excluded with the "unused export" comment when using export * as ...
Reproducible in vscode.dev or in VS Code Desktop?
- [X] Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- [ ] Not reproducible in the monaco editor playground
Monaco Editor Playground Code
No response
Actual Behavior
Steps to reproduce:
- Clone https://github.com/microsoft/monaco-editor
cd samples/browser-esm-webpack-monaco-plugin- Add file
file.jswith one lineexport * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; - Replace
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';inindex.jswithimport { monaco } from './file'; NODE_ENV=production npm run build
Result:
dist/main.bundle.js should contain
_common_network_js__WEBPACK_IMPORTED_MODULE_8__/* .RemoteAuthorities.setPreferredWebSchema */ .WX.setPreferredWebSchema(/^https:/.test(window.location.href) ? 'https' : 'http');
but instead it has
/* unused export .RemoteAuthorities.setPreferredWebSchema */ undefined(/^https:/.test(window.location.href) ? 'https' : 'http');
which cause a runtime error (you can open dist/index.html in browser to see)
You can switch between the old line in index.js and the new one to see the difference. Works similar in development mode.
Expected Behavior
Shouldn't exclude used exports
Additional Context
It's not the webpack bug https://github.com/webpack/webpack/issues/15346
Also, I can confirm that changing
...pre.map((include) => `require(${stringifyRequest(include)});`),
`module.exports = require(${stringifyRequest(`!!${remainingRequest}`)});`,
...post.map((include) => `require(${stringifyRequest(include)});`)
to
...pre.map((include) => `import(${stringifyRequest(include)});`),
`import * as xxx from ${stringifyRequest(`!!${remainingRequest}`)};`,
`export default xxx;`,
...post.map((include) => `import(${stringifyRequest(include)});`)
inside include.ts helps