Skip to content

Internal server error: Unable to write the service worker file. #212

@lupus78

Description

@lupus78

I have a fresh Nuxt 4.1.2 install, with @vite-pwa/nuxt. When I try to build the app I get this error: Unable to write the service worker file. '[BABEL] /tmp/cfa6ef3bf25b645aff61cc43267c146a/sw.js: Cannot find module '@babel/parser' The same error comes up in dev mode.

Is this a compatibility issue with Nuxt 4?

$ npm run build

> build
> nuxt build

Nuxt 4.1.2 with Nitro 2.12.6                                                                                                                      nuxi 8:04:00 PM
ℹ Building for Nitro preset: node-server                                                                                                         nuxi 8:04:01 PM
ℹ Building client...                                 
.....
ℹ vite v7.1.9 building SSR bundle for production...                                                                                                   8:04:03 PM
ℹ ✓ 67 modules transformed.                                                                                                                           8:04:04 PM
ℹ ✓ built in 449ms                                                                                                                                    8:04:04 PM
✔ Server built in 455ms                                                                                                                               8:04:04 PM
✔ Generated public .output/public                                                                                                               nitro 8:04:04 PM

 ERROR  Unable to write the service worker file. '[BABEL] /tmp/59218e41a55a202b421be7a6300957f7/sw.js: Cannot find module '@babel/parser'              8:04:04 PM
Require stack:
- /app/node_modules/@babel/core/lib/index.js'

    at writeSWUsingDefaultTemplate (node_modules/workbox-build/build/lib/write-sw-using-default-template.js:68:15)
    at async generateSW (node_modules/workbox-build/build/generate-sw.js:95:23)
    at async generateServiceWorker (/app/node_modules/vite-plugin-pwa/dist/index.js:208:23)
    at async _generateSW (/app/node_modules/vite-plugin-pwa/dist/index.js:234:5)
    at async Object.generateSW (/app/node_modules/vite-plugin-pwa/dist/index.js:348:14)
    at async regeneratePWA (/app/node_modules/@vite-pwa/nuxt/dist/shared/nuxt.da05c5d6.mjs:350:3)
    at async /app/node_modules/@vite-pwa/nuxt/dist/shared/nuxt.da05c5d6.mjs:601:9
    at async /app/node_modules/nuxt/dist/index.mjs:4658:7
    at async build (/app/node_modules/nitropack/dist/core/index.mjs:1716:3)
    at async /app/node_modules/nuxt/dist/index.mjs:4678:5
    at async build (/app/node_modules/nuxt/dist/index.mjs:7360:3)
    at async Object.run (/app/node_modules/@nuxt/cli/dist/chunks/build.mjs:76:5)
    at async runCommand (/app/node_modules/citty/dist/index.mjs:316:16)
    at async runCommand (/app/node_modules/citty/dist/index.mjs:307:11)
    at async runMain (/app/node_modules/citty/dist/index.mjs:445:7) 



 ERROR  Unable to write the service worker file. '[BABEL] /tmp/59218e41a55a202b421be7a6300957f7/sw.js: Cannot find module '@babel/parser'              8:04:04 PM
Require stack:
- /app/node_modules/@babel/core/lib/index.js'

here is my package.json

{
  "name": "my-app",
  "type": "module",
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "cleanup": "nuxt cleanup",
    "analyze": "nuxt analyze",
    "typecheck": "nuxt typecheck",
    "lint": "eslint .",
    "lint:fix": "eslint . --fix"
  },
  "dependencies": {
    "@nuxt/eslint": "^1.9.0",
    "@vite-pwa/nuxt": "^1.0.4",
    "@vueuse/core": "^13.9.0",
    "eslint": "^9.36.0",
    "nuxt": "^4.1.2",
    "vue": "^3.5.22",
    "vue-router": "^4.5.1",
    "zod": "^4.1.11"
  },
  "devDependencies": {
    "@vite-pwa/assets-generator": "^1.0.1"
  }
}

and nuxt.config.ts

export default defineNuxtConfig({
  modules: ['@nuxt/eslint', '@vite-pwa/nuxt'],
  devtools: { enabled: true },
  compatibilityDate: '2025-07-15',
  pwa: {
    manifest: {
      name: 'My App',
      short_name: 'My App',
      description: 'Lorem ipsum.',
      theme_color: '#ffffff',
      icons: [
        {
          src: 'pwa-192x192.png',
          sizes: '192x192',
          type: 'image/png'
        },
        {
          src: 'pwa-512x512.png',
          sizes: '512x512',
          type: 'image/png'
        }
      ]
    },
    devOptions: {
      enabled: true
    }
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions