next-server-only
v0.0.3
Published
This is a marker package to indicate that a module can only be used in Server Components. Can be used in pages/api by add 'next-pages-api' to webpack config.resolve.conditionNames. See: https://webpack.js.org/guides/package-exports/
Downloads
7
Readme
It can be used in pages/api.
Modify next.config.js
like below:
...
const NEXT_PAGES_API_CONDITION='next-pages-api'
...
...
webpack: (
config,
{buildId, dev, isServer, defaultLoaders, nextRuntime, webpack}
) => {
if (isServer && nextRuntime == 'nodejs') {
if (!config.resolve.conditionNames?.length) {
config.resolve.conditionNames = ['...'];
}
const idx = config.resolve.conditionNames.indexOf('...');
if (idx > -1) {
config.resolve.conditionNames.splice(idx, 0, NEXT_PAGES_API_CONDITION);
} else {
config.resolve.conditionNames.push(NEXT_PAGES_API_CONDITION);
}
}
return config
},
...