ChainSafe/js-libp2p-noise

bug: not importable via script tag from CDN

SgtPooki opened this issue · 4 comments

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'

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?

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

image

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