ai / nanoid

A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
https://zelark.github.io/nano-id-cc/
MIT License
24.62k stars 790 forks source link

Importing from Unpkg fails with 404 on `crypto` dependency. #290

Closed milochristiansen closed 3 years ago

milochristiansen commented 3 years ago

The very first line in the module returned by unpkg is:

import crypto from "https://unpkg.com/crypto@latest?module";

Which is a 404.

What is this "crypto" library, and where is it actually? I'm using import maps in my project so I can forcibly patch the issue if I know where to find the module I need.

For now I'm using the nanoid/non-secure package since that one is actually zero dependencies, but it obviously isn't ideal.

ai commented 3 years ago

You need to load /nanoid.js instead of /index.js.

Something like https://unpkg.com/nanoid/nanoid.js

milochristiansen commented 3 years ago

That does indeed work. I'm not sure why Unpkg would give me the wrong file by default. something is probably misconfigured.

ai commented 3 years ago

It gives you default file, but this file was created for Node.js and doesn’t work in browser.

You can ask Unpkg to support package.browser key.