You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
map: userModuleSourceMap,// give rollup acces to original user module source map
305
+
};
306
+
}else{
307
+
returnnull;
308
+
}
309
+
},
307
310
},
311
+
312
+
// People may use `module.exports` in their API routes or page files. Next.js allows that and we also need to
313
+
// handle that correctly so we let a plugin to take care of bundling cjs exports for us.
314
+
commonjs({
315
+
sourceMap: true,
316
+
strictRequires: true,// Don't hoist require statements that users may define
317
+
ignoreDynamicRequires: true,// Don't break dynamic requires and things like Webpack's `require.context`
318
+
ignore(){
319
+
// We basically only want to use this plugin for handling the case where users export their handlers with module.exports.
320
+
// This plugin would also be able to convert any `require` into something esm compatible but webpack does that anyways so we just skip that part of the plugin.
321
+
// (Also, modifying require may break user code)
322
+
returntrue;
323
+
},
324
+
}),
325
+
],
326
+
327
+
// We only want to bundle our wrapper module and the wrappee module into one, so we mark everything else as external.
// Prevent rollup from stressing out about TS's use of global `this` when polyfilling await. (TS will polyfill if the
331
+
// user's tsconfig `target` is set to anything before `es2017`. See https://stackoverflow.com/a/72822340 and
332
+
// https://stackoverflow.com/a/60347490.)
333
+
context: 'this',
334
+
335
+
// Rollup's path-resolution logic when handling re-exports can go wrong when wrapping pages which aren't at the root
336
+
// level of the `pages` directory. This may be a bug, as it doesn't match the behavior described in the docs, but what
337
+
// seems to happen is this:
338
+
//
339
+
// - We try to wrap `pages/xyz/userPage.js`, which contains `export { helperFunc } from '../../utils/helper'`
340
+
// - Rollup converts '../../utils/helper' into an absolute path
341
+
// - We mark the helper module as external
342
+
// - Rollup then converts it back to a relative path, but relative to `pages/` rather than `pages/xyz/`. (This is
343
+
// the part which doesn't match the docs. They say that Rollup will use the common ancestor of all modules in the
344
+
// bundle as the basis for the relative path calculation, but both our temporary file and the page being wrapped
345
+
// live in `pages/xyz/`, and they're the only two files in the bundle, so `pages/xyz/`` should be used as the
346
+
// root. Unclear why it's not.)
347
+
// - As a result of the miscalculation, our proxy module will include `export { helperFunc } from '../utils/helper'`
348
+
// rather than the expected `export { helperFunc } from '../../utils/helper'`, thereby causing a build error in
349
+
// nextjs..
350
+
//
351
+
// Setting `makeAbsoluteExternalsRelative` to `false` prevents all of the above by causing Rollup to ignore imports of
352
+
// externals entirely, with the result that their paths remain untouched (which is what we want).
353
+
makeAbsoluteExternalsRelative: false,
354
+
onwarn: (_warning,_warn)=>{
355
+
// Suppress all warnings - we don't want to bother people with this output
356
+
// Might be stuff like "you have unused imports"
357
+
// _warn(_warning); // uncomment to debug
308
358
},
359
+
});
309
360
310
-
// People may use `module.exports` in their API routes or page files. Next.js allows that and we also need to
311
-
// handle that correctly so we let a plugin to take care of bundling cjs exports for us.
312
-
commonjs({
313
-
sourceMap: true,
314
-
strictRequires: true,// Don't hoist require statements that users may define
315
-
ignoreDynamicRequires: true,// Don't break dynamic requires and things like Webpack's `require.context`
316
-
ignore(){
317
-
// We want basically only want to use this plugin for handling the case where users export their handlers with module.exports.
318
-
// This plugin would also be able to convert any `require` into something esm compatible but webpack does that anyways so we just skip that part of the plugin.
319
-
// (Also, modifying require may break user code)
320
-
returntrue;
321
-
},
322
-
}),
323
-
],
324
-
325
-
// We only want to bundle our wrapper module and the wrappee module into one, so we mark everything else as external.
0 commit comments