perry-mitchell / ulidx

ULID generator for NodeJS and the browser
MIT License
281 stars 17 forks source link

Error in 'crypto' discovery #9

Closed budarin closed 2 years ago

budarin commented 2 years ago

Trying to build may code and get the error:

  WARNING in ./node_modules/ulidx/dist/ulid.js 69:31-48
  Module not found: Error: Can't resolve 'crypto' in 'D:\Projects\myproject\node_modules\ulidx\dist' 

  BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
  This is no longer the case. Verify if you need this module and configure a polyfill for it.

  If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
  If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }
   @ ./node_modules/ulidx/dist/index.js 14:13-30
   @ ./src/client/index.tsx 4:0-34

also should add discovery crypto in workers

perry-mitchell commented 2 years ago

Hi,

This is documented in the readme - crypto should be disabled in webpack (not polyfilled).

I think a web build would be helpful, I might need to provide one soon. But for the time being please just block crypto in your resolve.fallback webpack config.

perry-mitchell commented 2 years ago

should add discovery crypto in workers

Web worker crypto detection is handled: https://github.com/perry-mitchell/ulidx/blob/c2d13849d5c3854b656e75ccb2b1c8cbadd20857/source/ulid.ts#L92