-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Intermittent "Uncaught ReferenceError: importShim is not defined" error #379
Comments
Thanks for reporting the issue - can you share which line of code is giving the bug? Also if you happen to discover it's as simple as a one-liner to bump the ordering of global assignment of |
Chrome doesn't point to any specific bugs in the ES Module Shims file:
The errors are not easy to reproduce in Chrome since they are intermittent. However, in the latest version of Firefox (115), which I just tested that code with, they appear to be persistent. By the way, I'm thinking of using the good old |
I’m running into the same problem. I can reproduce it when I delay serving I believe the way to fix is to ensure that the shim is to use <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/es-module-shims.min.js"></script> MDN says that
And
So when the inline module script is executed, the shim script has already been executed and I’ve tested it and it seems to do the trick. Should the documentation be updated? Here’s a server script to delay serving the shim: import http from "http";
import { promises as fsPromises } from "fs";
const server = http.createServer(async (req, res) => {
try {
await new Promise((resolve) => setTimeout(resolve, 3000));
res.statusCode = 200;
res.setHeader("Content-Type", "application/javascript");
res.setHeader("Access-Control-Allow-Origin", "*");
const fileContent = await fsPromises.readFile("./es-module-shims.js");
res.end(fileContent);
} catch (err) {
res.statusCode = 500;
res.end("Error reading file");
}
});
const port = 3000;
server.listen(port, () => {
console.log(`Server is running and listening on http://localhost:${port}`);
}); |
Hi there. Great work.
I'm not sure if this is a known issue, so apologies if it's a repeat. But I kept getting intermittent
Uncaught ReferenceError: importShim is not defined
errors while usingimportShim()
from the latest version of ES Module Shims (1.7.3) in the latest version of Chrome (114).I'm not sure if this is the best practice, but the errors seemed to disappear when I included ES Module Shims with a
defer
instead of anasync
attribute.The text was updated successfully, but these errors were encountered: