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

formatjs not compatible with ES Modules #2961

Closed
denisaStefan opened this issue Jun 8, 2021 · 3 comments
Closed

formatjs not compatible with ES Modules #2961

denisaStefan opened this issue Jun 8, 2021 · 3 comments

Comments

@denisaStefan
Copy link

I tried to integrate the formatjs library in my project, but I ran into problems because of the following:
The script that uses the library is loaded as a module. However, this is not working with the browser throwing the following error:
🚧 Browser logs on Chromium:
TypeError: Failed to fetch dynamically imported module
🚧 Browser logs on Webkit:
TypeError: 'application/json' is not a valid JavaScript MIME type.
🚧 Browser logs on Firefox:
TypeError: error loading dynamically imported module

The error is caused by the line:
digitMapping = tslib_1.__importStar(require("./digit-mapping.json"));

Modules are expecting js files and do not consider json a valid JavaScript MIME type.

I believe it could be beneficial to multiple people to have the imports changed so that the library could be loaded as module.

Thanks!

@longlho
Copy link
Member

longlho commented Jun 9, 2021

do you have a repro repo?

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Jun 24, 2021
@davidclark87
Copy link

davidclark87 commented Jun 25, 2021

I'm hitting this too, I will try to produce a minimal repro example tomorrow.

The issue is this is not a standard import - you can't import JSON (unless bundling your code with a tool like webpack):

import * as digitMapping from './digit-mapping.json'

https://github.com/formatjs/formatjs/blob/main/packages/ecma402-abstract/NumberFormat/format_to_parts.ts#L18

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

3 participants