File size: 570 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import type { ModuleLoader } from './module-loader'
/**
* Loads a module using `await require(id)`.
*/
export class NodeModuleLoader implements ModuleLoader {
public async load<M>(id: string): Promise<M> {
if (process.env.NEXT_RUNTIME !== 'edge') {
// Need to `await` to cover the case that route is marked ESM modules by ESM escalation.
return await (process.env.NEXT_MINIMAL
? // @ts-ignore
__non_webpack_require__(id)
: require(id))
}
throw new Error('NodeModuleLoader is not supported in edge runtime.')
}
}
|