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

Non-normalized URLs can cause sporadic behaviors in loading Modules #397

Closed
jvoccia opened this issue Nov 10, 2023 · 1 comment
Closed

Comments

@jvoccia
Copy link

jvoccia commented Nov 10, 2023

I have been tracking down an issue with es-module-shim and some sporadic behavior in an app that we are migrating from AMD to ESM.

I have a module located at the URL:
http://example.com/deps/PKG1/file.js

With the contents:

console.log('File Loaded');
export default 'File Loaded';

And an import-map that looks like:

{
    "imports": {
        "PKG1/": "./deps/PKG1/"
    }
}

Located at http://example.com/index.html

If I have a module that contains this:

import result from 'PKG1/file.js';
await import('http://example.com/deps/PKG1/./file.js');

The file at the URL: http://example.com/deps/PKG1/file.js
Will be loaded twice when using es-module-shim with a "shimmed import map and module."

This will result in the console log message "File Loaded" appearing twice.
But will only be loaded once with native handling Module handling in browsers, and only one console log message will appear.

In the scenario I had where this came into play, I was seeing an error in a file that looked like this throw an error like this:

import someVar from 'PKG1/file.js';
const f = someVar; // Error: Uncaught (in promise) ReferenceError: Cannot access 'someVar' before initialization

I am still not sure why I would be getting someVar is not initialized, but I assume it is a confluence of factors regarding the use of top level await, import.meta.resolve, and the import() function.

I realize this is an edge case, so I am altering our code to do file normalization, but wanted to make sure it at least got reported for the next person.

@guybedford
Copy link
Owner

This should be fixed inhttps://github.com//pull/398, thanks for posting.

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