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

Ambiguous import "x" has multiple matching exports when bundling Monaco Editor workers #723

Closed
yyx990803 opened this issue Jan 29, 2021 · 1 comment

Comments

@yyx990803
Copy link
Contributor

yyx990803 commented Jan 29, 2021

Reproduction:

npm install monaco-editor
esbuild node_modules/monaco-editor/esm/vs/language/css/css.worker.js --bundle --outfile=test.js

 > node_modules/monaco-editor/esm/vs/language/css/cssWorker.js: error: Ambiguous import "TextDocument" has multiple matching exports
    213 │                 return cssService.TextDocument.create(uri, this._languageId, model.version, model.getValue());
        ╵                                   ~~~~~~~~~~~~

1 error

Tracing the imports, it looks like technically the import isn't really ambiguous. The source of TextDocument is in node_modules/monaco-editor/esm/vs/language/css/_deps/vscode-languageserver-textdocument/lib/esm/main.js:

export var TextDocument;
(function (TextDocument) {
  // ...
})(TextDocument || (TextDocument = {}))

Even if this introduces certain ambiguity, it seems most other bundlers don't really care about it and can bundle it just fine (and the runtime also works just fine). In fact, it even loads properly over native browser ESM (via new Worker(..., { type: 'module' }) so at the very least I don't think esbuild should error out here.

evanw added a commit that referenced this issue Jan 30, 2021
@evanw
Copy link
Owner

evanw commented Jan 30, 2021

Thanks for the report. It does look like esbuild is handling this incorrectly. One of the exports that esbuild is flagging as a duplicate is supposed to be shadowing the other one. This is handled correctly if you import from the file directly but there's a bug when there are multiple levels of re-exports. I'll get this fixed.

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 a pull request may close this issue.

2 participants