node-localstorage icon indicating copy to clipboard operation
node-localstorage copied to clipboard

Missing browser entry and/or sideEffects:false in package.json

Open andersekdahl opened this issue 1 year ago • 0 comments

Hi! We're using node-localstorage in Next.js apps and noticed that node-localstorage ends up in our browser bundle. We've been able to remove it by doing some webpack tomfoolery and wanted to check if this instead can be fixed in the package?

One thing is having "sideEffects": false in package.json: https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free

Another thing would be to have a browser field in package.json that points to a file that basically just does this:

module.exports = window.localStorage;

webpack and other bundlers would then prefer that file when the build target is for the browser, and you wouldn't end up with the real node-localstorage in the browser bundles.

I would have contributed with a PR but my coffeescript skills are less than ideal.

andersekdahl avatar Nov 07 '23 08:11 andersekdahl