Is there something to enable to have next.js perform tree-shaking/removal of dead code from dependencies? I've exported two objects like this:
library.js
export const foo = {foo:"foo"}
export const bar = {bar:"bar"}
And in my next.js app I do like this:
page.tsx
import { foo } from 'library';
console.log(foo);
So now I'd expect a production-build will not include bar
, and indeed something appears to go right because this line is produced:
.next/server/chunks/621.js
/* unused harmony exports bar */
But confusingly when I load the app in the browser the network-traffic indicates the unused export is included:
http://localhost:3001/_next/static/chunks/pages/page-0b2b13a7513f2849d855.js
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([[3031], {
80621: function(e, r, n) {
"use strict";
...
const l = a.object({
foo: "foo"
});
a.object({
bar: "bar"
});
},
Why would the build identify unused exports but not remove them from the payload that's transferred to the browser? Is there a setting Next expects us to enable? Some sort of post-processing that actually prunes unused exports?