Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sideeffects: false to package.json #197

Closed
twavv opened this issue Dec 21, 2020 · 9 comments
Closed

Add sideeffects: false to package.json #197

twavv opened this issue Dec 21, 2020 · 9 comments

Comments

@twavv
Copy link

twavv commented Dec 21, 2020

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
Copy link

@travigd Can you use a dynamic import instead?

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

@twavv
Copy link
Author

twavv commented Jan 14, 2021

Yes, but this should still be fixed. :)

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

@rawr51919
Copy link

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

@ljharb
Copy link
Member

ljharb commented Feb 2, 2021

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

@rawr51919
Copy link

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

@ljharb
Copy link
Member

ljharb commented Feb 2, 2021

I'd think so.

@rawr51919
Copy link

PR #201 will fix this issue

@ljharb
Copy link
Member

ljharb commented Mar 5, 2024

Fixed in b638139

@ljharb ljharb closed this as completed Mar 5, 2024
@rawr51919
Copy link

Fixed in b638139

glad you got around to it thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants