Currently, I am utilizing Webpack's require.context
in order to eliminate redundancy while importing multiple pages. However, TypeScript is throwing an error stating that
Property 'context' does not exist on type 'NodeRequire'.
.
I attempted to address this issue by using declaration merging to include context
in NodeRequired
, following the guidelines outlined under "Merging Interfaces" in the TS docs. Despite implementing this solution, the error persists.
Below is a snippet of the relevant section of my code:
interface NodeRequire {
context(path: string): NodeRequire;
}
const pagesCtx = require.context("./pages/"); // The error is triggered here