Next.js Discord

Discord Forum

Adding additional entry to build

Unanswered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
I am trying to add an additional entry to the build in nextconfig for a service worker file i need to help with some auth functions for my app, therefore i modified the config as so:
const nextConfig = {
    webpack(config) {
        return {
            ...config,
            entry: async () => {
                return config.entry().then(entry => {
                    console.log(entry)
                    return ({
                        ...entry, 'public/service-worker': 'public/service-worker.ts'
                    })
                })
            }
        }
    }
}


this however results in the error
Error: Entry public/service-worker depends on main, but this entry was not found
`

I therefore tried changing it to
...
return ({
    ...entry, 'public/service-worker': {input: 'public/service-worker.ts', dependsOn: 'main'}
})

yet this gives the error

TypeError: q.import is not iterable
    at /Users/elliot/Documents/code/budgetApp/frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:205907
- error Error [TypeError]: q.import is not iterable
    at /Users/elliot/Documents/code/budgetApp/frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:205907 {
  digest: undefined
}


my service-worker.ts file currently just contains a console.log until i figure this out

So im wandering what is the correct way to go about adding an extra entry to build for my application?

0 Replies