For some inexplicable reason, the solution provided by @vially kept causing the server to exit, even though it successfully identified the _app
substring.
I made some slight modifications and managed to resolve my issue without having to guess the index anymore.
const path = require('path')
const nextConfig = {
// other settings...
webpack (config) {
// iterate through all rules and locate those with `oneOf` key
config.module.rules.forEach(rule => {
if (!rule.oneOf) return
rule.oneOf.forEach(one => {
if (!`${one.issuer?.and}`.includes('_app')) return
one.issuer.and = [path.resolve(__dirname)]
})
})
},
}
module.exports = nextConfig
Alternatively, if you prefer not to continue searching after finding the substring, you can replace the main forEach
with a for
loop and keep track of success using a variable. Once the substring is found, update the variable and exit the loop.
const path = require('path')
const nextConfig = {
// other settings...
webpack (config) {
let hasFound = false
for (let i = 0; i < config.module.rules.length; i++) {
const rule = config.module.rules[i]
if (!rule.oneOf) continue
rule.oneOf.forEach(one => {
if (!`${one.issuer?.and}`.includes('_app')) return
one.issuer.and = [path.resolve(__dirname)]
hasFound = true
})
if (hasFound) break
}
},
}
module.exports = nextConfig