nuxt-community / pwa-module

Zero config PWA solution for Nuxt.js
https://pwa.nuxtjs.org
MIT License
1.24k stars 171 forks source link

Named export 'defu' not found #558

Open DesertCookie opened 1 week ago

DesertCookie commented 1 week ago

I created a fresh Nuxt project using bun and installed PWA. When I run the application via npm run dev, I get the following error:

 ERROR  Named export 'defu' not found. The requested module 'defu' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'defu';
const { defu } = pkg;

  import { defu } from 'defu';
  ^^^^
  SyntaxError: Named export 'defu' not found. The requested module 'defu' is a CommonJS module, which may not support all module.exports as named exports.
  CommonJS modules can always be imported via the default export, for example using:

  import pkg from 'defu';
  const { defu } = pkg;

  at ModuleJob._instantiate (node:internal/modules/esm/module_job:171:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:254:5)
  at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:482:26)
  at async loadKit (/C:/Users/PROJECT_PATH/node_modules/nuxi/dist/shared/nuxi.f76c700d.mjs:5049:15)
  at async Object.run (/C:/Users/PROJECT_PATH/node_modules/nuxi/dist/chunks/dev.mjs:170:32)
  at async runCommand$1 (/C:/Users/PROJECT_PATH/node_modules/nuxi/dist/shared/nuxi.fefc5017.mjs:1648:16)
  at async runCommand$1 (/C:/Users/PROJECT_PATH/node_modules/nuxi/dist/shared/nuxi.fefc5017.mjs:1639:11)
  at async runMain$1 (/C:/Users/PROJECT_PATH/node_modules/nuxi/dist/shared/nuxi.fefc5017.mjs:1777:7)

This is my package.json:

{
  "name": "project",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --tunnel",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "nuxt": "^3.13.0",
    "vue": "latest",
    "vue-router": "latest"
  },
  "devDependencies": {
    "@nuxtjs/pwa": "^3.3.5"
  }
}

My nuxt.config.ts:

export default defineNuxtConfig({
    devtools: {enabled: true},
    buildModules: [
        '@nuxtjs/pwa',
    ],
    pwa: {
        manifest: {
            name: 'Immo-Projektmanagement',
            short_name: 'ImmoM',
            description: '',
            lang: 'de'
        },
        workbox: {},
        mobileAppIOS: true
    },
    compatibilityDate: '2024-09-09'
})

I was in the process of migrating an app to a PWA and had started a new project for that purpose to slowly transition all aspects of the app.

DesertCookie commented 1 week ago

Running npx nuxi upgrade --foce gives me a different error now:

node:internal/modules/esm/resolve:257
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\PROJECT_PATH\node_modules\nuxi\dist\shared\nuxi.fefc5017.mjs' imported from C:\Users\PROJECT_PATH\node_modules\nuxi\dist\index.mjs
    at finalizeResolution (node:internal/modules/esm/resolve:257:11)
    at moduleResolve (node:internal/modules/esm/resolve:914:10)
    at defaultResolve (node:internal/modules/esm/resolve:1038:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:554:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:523:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:126:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///C:/Users/PROJECT_PATH/node_modules/nuxi/dist/shared/nuxi.fefc5017.mjs'
}

Node.js v22.8.0

I have since upgraded my Node version which was formerly v21.x.

Edit: It's back to the Defu error.