For some obscure reason, @vially solution kept exiting the server, although it did found the _app
substring.
Therefore, I slightly modified it and fixed my problem. Also, no more guessing the index.
const path = require('path')
const nextConfig = {
// other settings...
webpack (config) {
// loop over all rules and find the ones 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
Or, if you don't want to continue search after you found the substring, replace main forEach
with for
loop and track success in a variable. Once you found the substring, update the variable and loop will exit.
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