browserify / crypto-browserify

partial implementation of node's `crypto` for the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add sideeffects: false to package.json

twavv opened this issue · comments

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.

@travigd Can you use a dynamic import instead?

export async function getServerSideProps() {
  const crypto = await import('crypto');
}

Yes, but this should still be fixed. :)

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

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

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

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

I'd think so.

PR #201 will fix this issue

Fixed in b638139

glad you got around to it thanks :)