primefaces / primevue

Next Generation Vue UI Component Library
https://primevue.org
MIT License
10.81k stars 1.24k forks source link

ERROR [worker reload] [worker init] ../.nuxt/dev/index.mjs failed #6712

Closed farahats9 closed 1 week ago

farahats9 commented 3 weeks ago

Describe the bug

Cannot run the project after adding primevue, the project is just the nuxt starter code and no other packages installed.

nuxt.config.ts

import Aura from '@primevue/themes/aura';

export default defineNuxtConfig({
    modules: [
        '@primevue/nuxt-module'
    ],
    primevue: {
        options: {
            theme: {
                preset: Aura
            }
        }
    }
})

I am using nuxt v3.13.2 vue latest (3.5) and primevue v4.2.1

It gives the error in the title and never loads the app in browser (stuck on the nuxt loading screen)

Reproducer

https://stackblitz.com/edit/nuxt-starter-vhvkfm

PrimeVue version

4.2.1

Vue version

4.x

Language

ALL

Build / Runtime

Nuxt

Browser(s)

All

Steps to reproduce the behavior

No response

Expected behavior

No response

molul commented 3 weeks ago

Having the exact same problem. Just started a Nuxt 3 project, then added PrimeVue following the docs, and I can't start it unless I remove PrimeVue.

EDIT: tried installing 4.1.1. Throws the same error. Can only continue by removing PrimeVue from the project.

wangziling commented 3 weeks ago

Yes, I have met the same issue, both under the developement/production mode.

I tried to install 4.2.0, 4.1.1, 4.1.0. All throw the same error.

Cannot access 'Mo' before initialization
  at useRuntimeConfig (/E:/Codes/xxx/.nuxt/dev/index.mjs:1:79646)
  at /E:/Codes/xxx/.nuxt/dev/index.mjs:1:48326
  at ModuleJob.run (node:internal/modules/esm/module_job:268:25)
  at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
  at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

image

Seems the issue caused by invoking the useRuntimeConfig() at the wrong phase.

Here: https://github.com/primefaces/primevue/blob/705361836a76b17b43c40b03d02b124ff4ed2159/packages/nuxt-module/src/module.ts#L105 I changed to const runtimeConfig = undefined;, works well.

Cannot use useRuntimeConfig(useEvent());, it throws Nitro request context is not available. Enable the experimental flag using experimental.asyncContext: true.

@molul I am using patch-package to patch the local-installed @primevue/nuxt-module line 242 to proceed my works. Modify the const runtimeConfig = useRuntimeConfig(); to const runtimeConfig = undefined;.

doug-shontz commented 3 weeks ago

Can confirm the fix by @wangziling . Strange that it wasn't happening earlier this week, but thankful for the quick workaround to keep moving!

Noxdor commented 3 weeks ago

Can confirm the same issue.

Ed1ks commented 3 weeks ago

same here. Didnt change anything in packages but suddently couldnt run fullstack debug. Love those bugs

j0rgedev commented 3 weeks ago

I also upgraded to 4.2.1 and I got: ERROR [worker reload] [worker init] C:/Users/j0rge/Desktop/my-project/.nuxt/dev/index.mjs failed I needed to downgrade to 4.1.1 and delete my .nuxt folder to make it run without errors. So, @wangziling don't forget also to delete the .nuxt folder, to make it work with 4.1.1

kiki-kanri commented 3 weeks ago

I guess it should be related to nitropack version 2.10, I installed nitropack version 2.9.7 and it works fine.

The problem is the location of the definition of useRuntimeConfig in the index.mjs file generated in version 2.10.

In version 2.9, the definition of useRuntimeConfig is at the top (at least it's not used anywhere above it).

image

In version 2.10, the location of the definition of useRuntimeConfig is no longer before any use, causing an error when primevue is used.

image

image

I'm not sure if this is a nitropack problem or a primevue one, but the current solution seems to be to downgrade the nitropack version to 2 9.7.

It looks like you can't use useRuntimeConfig in the top level, it has to be wrapped in a function, so it could be a problem with primevue, or nitropack (because of a change in the order of definitions).

This may affect more than just primevue's packages, so I'll try to open an issue there as well.

This is a description of nitro's use of useRuntimeConfig.

It seems to say that it can only be used in functions that start with define, but it's just that the way nitro builds itself allows useRuntimeConfig to be defined at the top, so there's no problem.

j0rgedev commented 3 weeks ago

@kiki-kanri i've just asked on twitter and pi0 said they're already investigating, so it seems to be a nitro problem

molul commented 3 weeks ago

Using 4.1.1 (previously deleting .nuxt folder, node_modules folfder and package-lock.json) doesn't fix the issue on my project. This is my package.json:

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --host",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "reinstall": "rm -rf node_modules .nuxt package-lock.json && npm i"
  },
  "dependencies": {
    "@nuxt/eslint": "^0.6.1",
    "@nuxt/icon": "^1.6.1",
    "@primevue/themes": "4.1.1",
    "husky": "^9.1.6",
    "nuxt": "^3.13.2",
    "primevue": "4.1.1",
    "tailwindcss-primeui": "^0.3.4",
    "vue": "latest",
    "vue-router": "latest"
  },
  "devDependencies": {
    "@commitlint/cli": "^19.5.0",
    "@commitlint/config-conventional": "^19.5.0",
    "@nuxtjs/tailwindcss": "^6.12.2",
    "@primevue/nuxt-module": "4.1.1",
    "lint-staged": "^15.2.10"
  }
}

I get the same error message.

kiki-kanri commented 3 weeks ago

Using 4.1.1 (previously deleting .nuxt folder, node_modules folfder and package-lock.json) doesn't fix the issue on my project. This is my package.json:

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --host",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "reinstall": "rm -rf node_modules .nuxt package-lock.json && npm i"
  },
  "dependencies": {
    "@nuxt/eslint": "^0.6.1",
    "@nuxt/icon": "^1.6.1",
    "@primevue/themes": "4.1.1",
    "husky": "^9.1.6",
    "nuxt": "^3.13.2",
    "primevue": "4.1.1",
    "tailwindcss-primeui": "^0.3.4",
    "vue": "latest",
    "vue-router": "latest"
  },
  "devDependencies": {
    "@commitlint/cli": "^19.5.0",
    "@commitlint/config-conventional": "^19.5.0",
    "@nuxtjs/tailwindcss": "^6.12.2",
    "@primevue/nuxt-module": "4.1.1",
    "lint-staged": "^15.2.10"
  }
}

I get the same error message.

Try install nitropack@2.9.7.

Here are the current solutions.

https://github.com/nuxt-hub/core/issues/363#issuecomment-2453086882

molul commented 3 weeks ago

Using 4.1.1 (previously deleting .nuxt folder, node_modules folfder and package-lock.json) doesn't fix the issue on my project. This is my package.json:

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --host",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "reinstall": "rm -rf node_modules .nuxt package-lock.json && npm i"
  },
  "dependencies": {
    "@nuxt/eslint": "^0.6.1",
    "@nuxt/icon": "^1.6.1",
    "@primevue/themes": "4.1.1",
    "husky": "^9.1.6",
    "nuxt": "^3.13.2",
    "primevue": "4.1.1",
    "tailwindcss-primeui": "^0.3.4",
    "vue": "latest",
    "vue-router": "latest"
  },
  "devDependencies": {
    "@commitlint/cli": "^19.5.0",
    "@commitlint/config-conventional": "^19.5.0",
    "@nuxtjs/tailwindcss": "^6.12.2",
    "@primevue/nuxt-module": "4.1.1",
    "lint-staged": "^15.2.10"
  }
}

I get the same error message.

Try install nitropack@2.9.7.

Here are the current solutions.

nuxt-hub/core#363 (comment)

It worked. Thanks!

j0rgedev commented 3 weeks ago

Using 4.1.1 (previously deleting .nuxt folder, node_modules folfder and package-lock.json) doesn't fix the issue on my project. This is my package.json:

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --host",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "reinstall": "rm -rf node_modules .nuxt package-lock.json && npm i"
  },
  "dependencies": {
    "@nuxt/eslint": "^0.6.1",
    "@nuxt/icon": "^1.6.1",
    "@primevue/themes": "4.1.1",
    "husky": "^9.1.6",
    "nuxt": "^3.13.2",
    "primevue": "4.1.1",
    "tailwindcss-primeui": "^0.3.4",
    "vue": "latest",
    "vue-router": "latest"
  },
  "devDependencies": {
    "@commitlint/cli": "^19.5.0",
    "@commitlint/config-conventional": "^19.5.0",
    "@nuxtjs/tailwindcss": "^6.12.2",
    "@primevue/nuxt-module": "4.1.1",
    "lint-staged": "^15.2.10"
  }
}

I get the same error message.

I didn't get the same error message since my nuxt project had already been created before. Sorry for that. Please try @kiki-kanri answer

mertsincan commented 3 weeks ago

Thank you for all the detailed reports and workarounds 👏 The comments contain very valuable insights. For now, let's wait for a response from NitroPack. Once we hear back, we can decide together on any changes needed.

I'm pinning this issue so we can also gather more user feedback in the meantime.

pi0 commented 3 weeks ago

✅ Nitro 2.10.1 is released with a fix. Recreating lock-file should solve the problem (tested against reproduction).

j0rgedev commented 3 weeks ago

I've just upgraded to primevue 4.2.1 and there were no errors. Thank you so much @pi0 🫱🏻‍🫲🏻.

wangziling commented 3 weeks ago

✅ Nitro 2.10.1 is released with a fix. Recreating lock-file should solve the problem (tested against reproduction).

Thanks~ 😉

mertsincan commented 3 weeks ago

Wow! Thank you so much for your effort! Nitro man, @pi0 🚀 https://x.com/mertsincan/status/1852881167642436066

lpknv commented 3 weeks ago

✅ Nitro 2.10.1 is released with a fix. Recreating lock-file should solve the problem (tested against reproduction).

Huge thanks!

luizzappa commented 3 weeks ago

@pi0 , I had a similar problem ( https://github.com/nuxt/nuxt/issues/29767 ) and this version 2.10.1 of Nitro solved it. However, alerts started to appear several times in the logs:

10:02:28.640    [plugin commonjs--resolver] It appears a plugin has implemented a "resolveId" hook that uses "this.resolve" without forwarding the third "options" parameter of "resolveId". This is problematic as it can lead to wrong module resolutions especially for the node-resolve plugin and in certain cases cause early exit errors for the commonjs plugin.
10:02:28.641    In rare cases, this warning can appear if the same file is both imported and required from the same mixed ES/CommonJS module, in which case it can be ignored.

My package.json:

 "overrides": {
    "vue": "^3.5.12",
    "nitropack": "2.10.1"
  }
pi0 commented 3 weeks ago

Solved in 2.10.2

luizzappa commented 3 weeks ago

Excellent! I just tested it and it was resolved

ejkgmea commented 2 weeks ago

Just delete yarn.lock or npm.lock file and reinstall the dependencies to upgrade the nitro to 2.10.2 or higher version and then the error will disappear

arshx86 commented 2 weeks ago

It is not solved, i don't think its because of primevue or other dependency, i am getting this error fully random not after installing a library. and it's basically unsolvable lol. Time to leave nuxt.

lpknv commented 2 weeks ago

It is not solved, i don't think its because of primevue or other dependency, i am getting this error fully random not after installing a library. and it's basically unsolvable lol. Time to leave nuxt.

Did you try setting up a fresh new project? I did and it vanished. I also updated npm and node just in case.

plcdnl commented 2 weeks ago

Also with 2.10.2 i continue to have the same error :(

j0rgedev commented 2 weeks ago

Hey @plcdnl. Could you share your config? Or maybe share your repo

plcdnl commented 2 weeks ago

Sorry @j0rgedev my problem was related to @nuxt/sanity

maximedotair commented 2 weeks ago

It is not solved, i don't think its because of primevue or other dependency, i am getting this error fully random not after installing a library. and it's basically unsolvable lol. Time to leave nuxt.

Same here ! It's complety random It works, it works, and then suddenly it stops working for no reason!

Are you on WSL with admin rights that change on your machine?

arshx86 commented 2 weeks ago

@maximedotair no, i'm on local with fresh nuxt project. It started happening again. Actually it has fix but it doesn't tell you what is the issue, check your syntax at @/server folder if any. Life could be much easier if it would tell where is the damn error lol.

@lpknv I dont think i want to move my code to new project every damn time this happens, there is issue behind but it hides. Rather than telling the error it shutdowns whole project.

Check your server directory, there should be something wrong. Good luck with finding as it does not tell.

Adding this to package.json has fixed the issue, at least it told me where is the error.

"overrides": {
  "nitropack": "2.9.7"
}
j0rgedev commented 2 weeks ago

For those who are still having issues. Could you share any reproduction?

llds66 commented 2 weeks ago

I tried Nuxt related projects https://github.com/ZTL-UwU/shadcn-docs-nuxt, github.com/nuxt-ui-pro/docs, and the same error occurred image

lpknv commented 1 week ago

I created a fresh nuxt 3.14 project, installed primevue and it works.

Here is the package.json file

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "@primevue/themes": "^4.2.1",
    "nuxt": "^3.14.159",
    "primevue": "^4.2.1",
    "vue": "latest",
    "vue-router": "latest"
  },
  "devDependencies": {
    "@primevue/nuxt-module": "^4.2.1"
  }
}

Here is the nuxt.config.ts file

import Aura from '@primevue/themes/aura';

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2024-04-03',
  devtools: { enabled: true },
  modules: ['@primevue/nuxt-module'],
  primevue: {
    options: {
      theme: {
        preset: Aura,
      },
    },
  },
});

And finally a Button in the app.vue

<template>
  <div>
    <Button label="Submit" />
  </div>
</template>
patrikrufino commented 6 days ago

✅ Nitro 2.10.1 is released with a fix. Recreating lock-file should solve the problem (tested against reproduction).

Work for me, thanks man

bryan487 commented 12 hours ago

I think this happend because nitropack, I just solved this problem by added these lines to my package.json, then recreate my package-lock.json:

"overrides": { "nitropack": "2.9.7" }

maximedotair commented 9 hours ago

After turning the problem upside down, what finally solved the problem was to check that my postgres database used via nuxt in Prisma was online and to generate the models via npx Prisma generate.

j0rgedev commented 33 minutes ago

@maximedotair yes. I forgot to mention that. I was also having that problem and it's just a nuxt issue since it's not showing the real error; however, if you create a simple nitro app and replicate the issue, it does show the error