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

SyntaxError: import not found, and no hint as to which file this happens in. #186

Closed
trusktr opened this issue Sep 17, 2021 · 6 comments
Closed

Comments

@trusktr
Copy link

trusktr commented Sep 17, 2021

I'm getting an error like this, and we can see that it isn't helping because it provides no indication as to which file is trying to do the import, or which file doesn't have the default export.

Uncaught Error: SyntaxError: import not found: default (blob:http://localhost:9876/9f08970d-6ed9-4d23-891b-37232270b698:1)
    onerror http://localhost:9876/base/node_modules/mocha/mocha.js:30574
    on http://localhost:9876/base/node_modules/mocha/mocha.js:30573
    _addEventListener http://localhost:9876/base/node_modules/mocha/mocha.js:23882
    run http://localhost:9876/base/node_modules/mocha/mocha.js:24770
    _callee$/< http://localhost:9876/base/node_modules/mocha/mocha.js:24836
    _callee$ http://localhost:9876/base/node_modules/mocha/mocha.js:24835
    tryCatch http://localhost:9876/base/node_modules/mocha/mocha.js:13007
    invoke http://localhost:9876/base/node_modules/mocha/mocha.js:13224
    defineIteratorMethods http://localhost:9876/base/node_modules/mocha/mocha.js:13060
    asyncGeneratorStep http://localhost:9876/base/node_modules/mocha/mocha.js:2337
    _next http://localhost:9876/base/node_modules/mocha/mocha.js:2359
    _asyncToGenerator http://localhost:9876/base/node_modules/mocha/mocha.js:2366
    _asyncToGenerator http://localhost:9876/base/node_modules/mocha/mocha.js:2355
    runAsync http://localhost:9876/base/node_modules/mocha/mocha.js:24848
    _callee$ http://localhost:9876/base/node_modules/mocha/mocha.js:30017
    tryCatch http://localhost:9876/base/node_modules/mocha/mocha.js:13007
    invoke http://localhost:9876/base/node_modules/mocha/mocha.js:13224
    defineIteratorMethods http://localhost:9876/base/node_modules/mocha/mocha.js:13060
    asyncGeneratorStep http://localhost:9876/base/node_modules/mocha/mocha.js:2337
    _next http://localhost:9876/base/node_modules/mocha/mocha.js:2359
    _asyncToGenerator http://localhost:9876/base/node_modules/mocha/mocha.js:2366
    _asyncToGenerator http://localhost:9876/base/node_modules/mocha/mocha.js:2355
    runAsync http://localhost:9876/base/node_modules/mocha/mocha.js:30047
    run http://localhost:9876/base/node_modules/mocha/mocha.js:30056
    run http://localhost:9876/base/node_modules/mocha/mocha.js:30694
    createMochaStartFn http://localhost:9876/base/node_modules/karma-mocha/lib/adapter.js:216
    loaded http://localhost:9876/debug.js:27
    <anonymous> http://localhost:9876/debug.html:52

This is very hard to debug. Can the error message be improved so that it also shows the importer and/or importee file names?

EDIT: Oh, wait, I think that's what blob:http://localhost:9876/9f08970d-6ed9-4d23-891b-37232270b698 is supposed to be, and I'm not sure where that's coming from. I'll close this, because it seems that the information is there and nothing to do with the polyfill.

@trusktr
Copy link
Author

trusktr commented Sep 17, 2021

Random thought: is Mocha perhaps swallowing the stack by throwing a new error with its own stack?

@trusktr trusktr closed this as completed Sep 17, 2021
@trusktr
Copy link
Author

trusktr commented Sep 17, 2021

The limited error message is due to es-module-shims providing a limited message. I tested in shim mode, and I see this:

Uncaught SyntaxError: import not found: default (3807d12d-cba0-436e-b285-34147b825f55:1:7)
    B es-module-shims.js:684
    (Async: setTimeout handler)
    B es-module-shims.js:684
    (Async: promise callback)
    processScript es-module-shims.js:682
    <anonymous> es-module-shims.js:718
    (Async: MutationCallback)
    <anonymous> es-module-shims.js:713
    <anonymous> es-module-shims.js:2

This is not specifying the importer or the importee, making debugging difficult.

@trusktr trusktr reopened this Sep 17, 2021
@trusktr
Copy link
Author

trusktr commented Sep 17, 2021

Hmmm, maybe it is not esms's fault? I'm not sure. I was running in Firefox, but the error is better in Chrome:

Uncaught SyntaxError: The requested module 'blob:http://localhost:9876/9c2b3e42-be5c-4d6d-ab05-49cef9ae6559' does not provide an export named 'default'

That's still difficult though. Is esms making that blob?

@trusktr
Copy link
Author

trusktr commented Sep 17, 2021

After turning off es-module-shims in Chrome, I was able to discover the source name of the module that didn't have a default export. esms errors are very difficult to debug.

@guybedford
Copy link
Owner

We include source maps, so Chrome has the information to provide a better error. It's actually a browser issue that these errors are so bad - there is nothing this project can do about it!

@trusktr
Copy link
Author

trusktr commented Sep 21, 2021

Aah, and I had source maps turned off. Thanks.

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

No branches or pull requests

2 participants