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

bug: not importable via script tag from CDN #296

Closed
SgtPooki opened this issue Mar 22, 2023 · 4 comments · Fixed by #297
Closed

bug: not importable via script tag from CDN #296

SgtPooki opened this issue Mar 22, 2023 · 4 comments · Fixed by #297

Comments

@SgtPooki
Copy link

even the URL from your README.md is throwing an error:

image

see ipfs-examples/helia-examples#13 where the only module I couldn't import via unpkg, skypack, or jsdelivr is this package.

when importing from typical CDNs, the files are not appropriately configured for ESM imports on the web, and you will get errors like:

  • import {noise} from 'https://cdn.jsdelivr.net/npm/@chainsafe/libp2p-noise@11.0.1/dist/src/index.js' -> Uncaught TypeError: Failed to resolve module specifier "it-pb-stream". Relative references must start with either "/", "./", or "../".
  • <script src="https://cdn.jsdelivr.net/npm/@chainsafe/libp2p-noise@11.0.1/dist/src/index.js" type="module" defer></script> -> Uncaught TypeError: Failed to resolve module specifier "it-pb-stream". Relative references must start with either "/", "./", or "../".

In order to import from CDN, the best provider I found was esm.sh via `import { noise } from 'https://esm.sh/v111/@chainsafe/libp2p-noise@11.0.1/es2022/libp2p-noise.js'

@mpetrunic
Copy link
Member

Hmm I get bundlephobia error with all other libp2p libs:

Why aren't you importing, in your example, noise like all other dependencies from /dist/index.min.js instead of /dist/src/index.js?

@SgtPooki
Copy link
Author

@mpetrunic because it doesn't exist. maybe that's the bug?

image

@SgtPooki
Copy link
Author

image

@mpetrunic
Copy link
Member

@SgtPooki You are right, indeed. Opened PR with fix #297 Thnx for reporting^^

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

Successfully merging a pull request may close this issue.

2 participants