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

Failed to import - h3-js #250

Closed
YousefED opened this issue Jan 17, 2022 · 4 comments
Closed

Failed to import - h3-js #250

YousefED opened this issue Jan 17, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@YousefED
Copy link

Failing module

  • npm: h3-js

h3-js fails to import from a browser environment. You can see that the official esm build (https://unpkg.com/[email protected]/dist/h3-js.es.js) optionally imports the fs module, but only when in a node-based environment. My guess is that the esm.sh version always imports the fs module, and therefore breaks.

import * as h3 from 'https://esm.sh/h3-js'

Error message

Error: 500 https://cdn.esm.sh/error.js?type=unsupported-nodejs-builtin-module&name=fs&importer=h3-js at http://127.0.0.1:3000/static/js/15.chunk.js:457:28

Additional info

  • esm.sh version: v62
@YousefED YousefED added the bug Something isn't working label Jan 17, 2022
@ije ije closed this as completed in 2206428 Jan 18, 2022
@ije
Copy link
Member

ije commented Jan 18, 2022

@YousefED thanks, now it works

@YousefED
Copy link
Author

@YousefED thanks, now it works

Wow awesome, thanks for the quick response!

Trying to understand the issue and inner workings of esm.sh, can you explain why in esm.sh the fs library is imported at all? While in https://unpkg.com/[email protected]/dist/h3-js.es.js the fs library is optionally imported? I assume this is because esbuild compiles the library with different settings than the original module?

Does esm.sh reuse ESM compatible outputs from the module (i.e.: h3-js.es.js), or does it always recompile the entire source?

@ije
Copy link
Member

ije commented Jan 18, 2022

in this issue, h3 code includes require('fs') that will be transform to import fs from "fs"

@ije
Copy link
Member

ije commented Jan 18, 2022

it transpiles code follow the js file defined by main and module in the package.js, just transform cjs -> esm and import deps with URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants