crypto-browserify icon indicating copy to clipboard operation
crypto-browserify copied to clipboard

Add sideeffects: false to package.json

Open twavv opened this issue 5 years ago • 7 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.

twavv avatar Dec 21 '20 02:12 twavv

@travigd Can you use a dynamic import instead?

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

mitchheddles avatar Jan 14 '21 03:01 mitchheddles

Yes, but this should still be fixed. :)

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

twavv avatar Jan 14 '21 03:01 twavv

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

rawr51919 avatar Feb 02 '21 14:02 rawr51919

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

ljharb avatar Feb 02 '21 15:02 ljharb

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

rawr51919 avatar Feb 02 '21 15:02 rawr51919

I'd think so.

ljharb avatar Feb 02 '21 15:02 ljharb

PR #201 will fix this issue

rawr51919 avatar Feb 02 '21 15:02 rawr51919

Fixed in b638139cc86e560ce65533c00e5f72b95926ff59

ljharb avatar Mar 05 '24 19:03 ljharb

Fixed in b638139

glad you got around to it thanks :)

rawr51919 avatar Mar 05 '24 22:03 rawr51919