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

Browser error "The requested module 'local-time' does not provide an export named 'default'" #162

Closed
epugh opened this issue Feb 1, 2024 · 3 comments

Comments

@epugh
Copy link

epugh commented Feb 1, 2024

I'm updating local_time for my opensource project Quepid, and this is the first time enabling importmaps. I am attempting to run sprockets and importmaps next to each other, so for importmaps I have a application2.js file.

In chrome I get this error in the console:

Uncaught SyntaxError: The requested module 'local-time' does not provide an export named 'default' (at application2-63b9b5e9196a96eb0dc8c6ea2d0ffeb417e0e2e284501f0943faa6765ce1c6ad.js:4:8)

While in Firefox I get:

Uncaught SyntaxError: ambiguous indirect export: default

Both refer to this line in my application2.js file:

import LocalTime from "local-time"

Looking at the rendered HTML it seems to make sense:
image

The PR that demonstrates my changes is o19s/quepid#939

Would love any advice!

@epugh
Copy link
Author

epugh commented Feb 1, 2024

Some days it feels like when you open the issue, that's when you find the page that answers your problem. There appears to be a bug, and I found some tips on #113 that worked.

Specifically, I changed my pin to pin "local-time", to: "vendored-local-time.js"# @3.0.2 and renamed vendor/javascript/local-time.js to vendor/javascript/vendored-local-time.js and it all started working!

@josefarias
Copy link
Contributor

josefarias commented Feb 1, 2024

@epugh I see in your PR you have multiple configurations that seem to be conflicting with each other.

The latest version of your PR has you linking the library in both your sprockets manifest and in importmaps.rb. In sprockets, you're linking the UMD build, while in importmaps you're linking the vendored version, which is the ESM build. These are not meant to work together, you should pick one instead.

Further, in the image you shared, you're linking to the UMD version from your importmap. I'd assume that's from a previous version of the PR.

The problem in #113 should not be present anymore. We use the standard configuration in HEY, in production. And the fix in #113 (EDIT: meaning the new release, not the temporary renaming fix) seems to have worked for other reporters. I think this points to a misconfiguration in your app.

You should be able to just have this in your importmap:

pin "local-time" # @3.0.2

Plus the vendored ESM build in ./vendor/javascript/local-time.js. That should be enough as long as you're not also importing the library some other way.

Closing for now but let me know if you find a way to reproduce in a more minimal setup that doesn't potentially conflict with loading the library. I'll gladly take another look.

Note that you can also choose to use sprockets without importmaps following these instructions: #161

@epugh
Copy link
Author

epugh commented Feb 1, 2024

Thanks for spotting the umd vs esm issue. I changed the order to first having application.js managed by Sprockets and then application2.js by importmaps and that seems to load the esm version. I appreciate the help!

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