Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt.js 2 + nuxt-vite + pinia error #690

Open
maxdzin opened this issue Sep 22, 2021 · 6 comments
Open

Nuxt.js 2 + nuxt-vite + pinia error #690

maxdzin opened this issue Sep 22, 2021 · 6 comments
Labels
bug Something isn't working contribution welcome ⛰ pkg:nuxt Related to @pinia/nuxt upstream The fix depends on a dependency vue 2.x Specific to Vue 2 usage

Comments

@maxdzin
Copy link

maxdzin commented Sep 22, 2021

Reproduction

Thank you so much for such a great state managing lib for Vue.
Pinia works well with Nuxt as well. However, when I tried to use it along with nuxt-vite, an issue happen from the start.
I tried with the fresh install and also, there is a reproduction link to Codesandbox:

Steps to reproduce the behavior

  1. Initialize a fresh Nuxt universal app + install the dependencies (the latest versions are used at the moment):
    "dependencies": { "@nuxtjs/composition-api": "^0.29.2", "@pinia/nuxt": "0.0.2", "nuxt": "^2.15.8", "pinia": "^2.0.0-rc.9" }, "devDependencies": { "nuxt-vite": "^0.2.4" }
  2. Add required modules into "buildModules" section of nuxt.config,js:
    buildModules: ["nuxt-vite", "@nuxtjs/composition-api/module", "@pinia/nuxt"],
  3. Run npm run dev
  4. See the error

Expected behavior

The app launched correctly with listed modules/configurations.

Actual behavior

The app won't launch because of the error.
This is comes in the console:
Uncaught SyntaxError: The requested module '/node_modules/pinia/dist/pinia.cjs?import' does not provide an export named 'defineStore'

Additional information

node version is 14.17.3
npm version is 7.24.0

@posva posva added the need repro This issue couldn't be reproduced label Sep 22, 2021
@posva
Copy link
Member

posva commented Sep 22, 2021

I'm glad you like it !
I need a boiled down repro to check

@maxdzin
Copy link
Author

maxdzin commented Sep 23, 2021

Hi @posva
OK. I've created a repo for that. You can check it here: https://github.com/spirico/nvp-test.git

@posva posva added bug Something isn't working and removed need repro This issue couldn't be reproduced labels Sep 23, 2021
@posva
Copy link
Member

posva commented Sep 23, 2021

It seems to be importing the wrong file of pinia but I'm not sure of why, could be a bug of nuxt-vite too.

@posva posva added upstream The fix depends on a dependency contribution welcome labels Sep 30, 2021
@posva posva changed the title Nuxt.js + nuxt-vite + pinia error Nuxt.js 2 + nuxt-vite + pinia error Oct 7, 2021
@tobiasdiez
Copy link

In the same setting (Nuxt 2 + vite) but with the most recent version of pinia, I got the following error Cannot read properties of undefined (reading 'install') in Function.Vue.use.

The relevant part of the generated server.js file looks as follows:

// --------------------
// Request: /@id/defaultexport:D:/Programming/JabRefOnline/node_modules/@pinia/nuxt/dist/templates/plugin.mjs
// Parents: 
// - /.nuxt/index.js ($id_d8486045)
// Dependencies: 
// - /node_modules/vue-demi/lib/index.mjs ($id_4c439bf5)
// - /node_modules/pinia/dist/pinia.mjs ($id_b1920624)
// --------------------
const $id_42c572ca = async function (global, __vite_ssr_exports__, __vite_ssr_import_meta__, __vite_ssr_import__, __vite_ssr_dynamic_import__, __vite_ssr_exportAll__) {
const module = __createCJSModule__(__vite_ssr_exports__)
const __vite_ssr_import_0__ = await __vite_ssr_import__("/node_modules/vue-demi/lib/index.mjs");

const __vite_ssr_import_1__ = await __vite_ssr_import__("/@id/pinia/dist/pinia.mjs/dist/pinia.mjs");

if (__vite_ssr_import_0__.isVue2) {
  __vite_ssr_import_0__.Vue2.use(__vite_ssr_import_1__.PiniaVuePlugin);
}

The problem is the strange import statement for pinia. In fact, if I remove the following
https://github.com/posva/pinia/blob/bd9a8a43b31163246d8a101aa27a94b86bfac4fd/packages/nuxt/src/index.ts#L31-L33
then the generated import reads

const __vite_ssr_import_1__ = await __vite_ssr_import__("/node_modules/pinia/dist/pinia.mjs");

and the error is gone.

tobiasdiez added a commit to tobiasdiez/pinia that referenced this issue Nov 7, 2021
The explicit nuxt alias leads to problems with nuxt/bridge (using vite) as descirbed here vuejs#690 (comment).

Reverts vuejs@438b16d
Fixes vuejs#690.
@posva posva added the ⛰ pkg:nuxt Related to @pinia/nuxt label Jan 27, 2022
@antlionguard
Copy link

there's any update for this issue and pr #781?

@posva posva added vue 2.x Specific to Vue 2 usage need repro This issue couldn't be reproduced labels Jul 7, 2022
@Ttou
Copy link

Ttou commented Jul 25, 2022

@posva https://stackblitz.com/github/Ttou/nuxt2-pinia-issue

@posva posva removed the need repro This issue couldn't be reproduced label Jul 25, 2022
@github-project-automation github-project-automation bot moved this to 🆕 Triaging in Pinia Roadmap Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contribution welcome ⛰ pkg:nuxt Related to @pinia/nuxt upstream The fix depends on a dependency vue 2.x Specific to Vue 2 usage
Projects
Status: Vue 2
Development

Successfully merging a pull request may close this issue.

5 participants