browserify / crypto-browserify

partial implementation of node's `crypto` for the browser
MIT License
653 stars 199 forks source link

Add sideeffects: false to package.json #197

Closed twavv closed 6 months ago

twavv commented 3 years ago

See title.

Allows for deadcode elimination when not the module is imported but not actually used.

This comes up for me when using NextJS where one frequently writes server side code as a getServerSideProps function. I want to import Node's crypto module but don't need it for the browser -- but webpack is unable to remove the import even though Next does remove the getServerSideProps function).

The workaround is to add

module.exports = {
  node: {
    crypto: "empty"
  }
}

to the webpack config.

mitchheddles commented 3 years ago

@travigd Can you use a dynamic import instead?

export async function getServerSideProps() {
  const crypto = await import('crypto');
}
twavv commented 3 years ago

Yes, but this should still be fixed. :)

I'm currently just using the webpack workaround described above.

rawr51919 commented 3 years ago

Could probably integrate this into PR #200 tbh. Will here shortly

ljharb commented 3 years ago

Probably best not to conflate multiple things in the same PR.

rawr51919 commented 3 years ago

Would it be best to rather make a separate PR after #200 is pushed to have this fixed?

ljharb commented 3 years ago

I'd think so.

rawr51919 commented 3 years ago

PR #201 will fix this issue

ljharb commented 6 months ago

Fixed in b638139cc86e560ce65533c00e5f72b95926ff59

rawr51919 commented 6 months ago

Fixed in b638139

glad you got around to it thanks :)