-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug]: Nuxt 3 version 3.1.2: nuxt instance unavailable - useNuxtApp().$app.filters #21196
Comments
Any help here @storybookjs/vue ? |
I will be working on it... but this may be a vite issue, I'm not sure but I will reproduce it and see! |
@chakAs3 we are talking about importing composable useNuxtApp |
Hi @Ibochkarev it won't work like this there is some workaround to do in vite config, but it is not the proper way it is just mocking. nuxt implementation still not yet done. |
@chakAs3 And when will we be able to come up with an alternative? We have a DI container in useNuxtApp, in which the entire core architecture of the project is located. And it is impossible to emulate it in every story |
yes @cwe-spb it is in our plan to do that properly, so I would like you to share your architecture with us earlier so we can have it in mind. |
I have the same issue, I have some components working with my nuxt project, but now I am adding one with 'useNuxtApp' in it (pulling in a plugin) and it fails. My component has this: const { $debounce } = useNuxtApp() And my preview.ts is like this: import { setup } from '@storybook/vue3'
import { createPinia } from 'pinia'
// import { useNuxtApp } from '#app'
// import { useNuxtApp } from 'nuxt/dist/app'
/**
* This is used by the preview panel in the storybook UI.
* Setup global deps for previewing components here, to avoid duplication.
*/
/** @type { import('@storybook/vue3').Preview } */
const preview: import('@storybook/vue3').Preview = {
parameters: {
backgrounds: {
default: 'light',
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
}
export default preview
const pinia = createPinia()
// const { $debounce } = useNuxtApp()
setup((app) => {
app.use(pinia)
// app.use($debounce)
})
// NOTE: I have commented out my attempt to import useNuxtApp function And I get 'useNuxtApp is undefined.' As you can see, I've tried providing it to the preview setup. If I uncomment the lines above that import the useNuxtApp function into preview.ts then I get this error:
|
@chakAs3 I've been trying to create a repro for you, let me know if you need something more, or were looking for something else. https://github.com/FieldMarshallVague/sb-nuxtapp-repro PLEASE NOTE: yarn build will break if the '#build' line in vite.config.ts is left. Comment it out for build, but leave it in for running story to see error below. I got nuxt working to a point with auto-imports based on advice from here But while simple components work fine, stories with more complex ones that include nuxt plugins (from the plugins folder, i.e. functions you want to be globally available) need the nuxtapp instance. NOTE: I could in this example use a composable instead, but this is just an example of requiring nuxtapp. The beta has changed since I created my project, but I've applied some config to it to recreate the fundamental issue of NuxtApp not being provided correctly (or so it seems). Storybook runs fine, but the preview panel shows an error:
I hope this helps :) |
Hi @FieldMarshallVague i really appreciate your work, it definetly helps, i will get sometime this week to work on it. i know the nuxtapp issue i have already some ideas to make it work properly. i let you know if i need your help on something . Thanks again |
@chakAs3 Good afternoon Is there any news on correcting the errors set forth in this issue |
Hello @Ibochkarev |
@chakAs3 Good afternoon Is there any news on correcting the errors set forth in this issue |
@chakAs3 Hey! This problem is still relevant. We can't use composable useNuxtApp() in storybook stories. This severely limits the ability to use storybook with Nuxt 3. Are there any options to make it work? |
Hi @cwe-spb it is not an issue of composable, but nuxt configuration that may have some conflicts with storybook, when it comes to composables you can check this repo https://github.com/chakAs3/vue3-sb-composable |
@chakAs3 Hi! Many of my components use |
Hi @VegasChickiChicki I put |
Thank you so much for your work! This is very important for . |
@chakAs3 Good afternoon Is there any news on correcting the errors set forth in this issue |
hi @Ibochkarev did you try |
@chakAs3 it work just with nuxt 2. For nuxt-3 isn't work. Or i am wrong? |
no @cwe-spb it works mainly for Nuxt 3, but should work for both i did not test it for Nuxt 2 |
@chakAs3 hello! tried it on a working project
|
@Ibochkarev i don't see @storybook-vue/nuxt here you need to install latest version v0.1.0 |
@chakAs3 hello "devDependencies": {
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@namics/stylelint-bem": "^9.0.0",
"@nuxt/test-utils-edge": "3.7.4-28244742.f000e8b6",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@pinia-plugin-persistedstate/nuxt": "^1.1.1",
"@storybook/addon-a11y": "^7.4.1",
"@storybook/addon-essentials": "next",
"@types/lodash": "^4.14.198",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@vueuse/nuxt": "^10.4.1",
"commitizen": "^4.3.0",
"cz-customizable": "^7.0.0",
"eslint": "8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-storybook": "^0.6.13",
"happy-dom": "^11.0.6",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"lint-staged": "^14.0.1",
"nuxt": "^3.7.3",
"nuxt-vitest": "^0.10.5",
"prettier": "^3.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.67.0",
"storybook-addon-designs": "^6.3.1",
"stylelint": "^15.10.3",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-standard-scss": "^11.0.0",
"stylelint-order": "^6.0.3",
"stylelint-prettier": "^4.0.2",
"stylelint-scss": "^5.1.0",
"stylelint-selector-bem-pattern": "^3.0.1",
"typescript": "^5.2.2",
"vitest": "0.33.0",
"vitest-environment-nuxt": "^0.10.5",
"storybook": "next",
"@types/node": "^18.17.5",
"@storybook/vue3": "next",
"@storybook-vue/nuxt": "rc",
"@storybook-vue/nuxt-storybook": "rc",
"@storybook/addon-interactions": "next",
"@storybook/addon-links": "next",
"@storybook/blocks": "next",
"@storybook/builder-vite": "next",
"@storybook/testing-library": "^0.2.0"
}, .storybook/main.ts import type { StorybookConfig } from "@storybook-vue/nuxt";
const config: StorybookConfig = {
stories: [
'../stories/**/*.stories.mdx',
'../stories/**/*.stories.@(js|jsx|ts|tsx)',
'../src/shared/ui/**/*.stories.@(js|jsx|ts|tsx)',
'../src/entities/**/*.stories.@(js|jsx|ts|tsx)',
'../src/widgets/**/*.stories.@(js|jsx|ts|tsx)',
],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook-vue/nuxt",
options: {},
},
docs: {
autodocs: "tag",
},
};
export default config; |
okay, I've done a bit of testing on the nuxtjs/storybook package and it does not support nuxt plugins. so please can you create a nuxt plugin like so in the /plugins folder. call it anything. with the following code.
and then try to use the plugin in a component like MyComposable like so.
I hope this is a good demostraion of what the problem is. |
Hi @RGaskinLtd would please you the latest versions this seems old. |
I run my test on that exact page with the provide ide |
if you do the same you will see pretty fast :) |
Yes my bad, this example is not up to date |
ahh okay. let me pull down the repo and try again |
okay using this repo https://github.com/nuxt-modules/storybook#readme I used the code I provide above. if there's anything I'm missing let me know but the result I get is this.
|
yes it should be fine, here is the repo maybe some issue with stackblitz i could not update it |
composables work fine. it's just plugins |
not sure how to fix it myself tbh been trying for days to intergrate storybook into an existing nuxt3 project with no luck. |
@chakAs3 Hello After installation and going to the component description tabs I get an error ERROR Internal server error: At least one <template> or <script> is required in a single file component. 10:38:06 AM
Plugin: vite:vue
File: /Users/ibochkarev/Projects/v3/src/widgets/templates/w-feed-template/w-feed-template.vue This error is displayed in all VUE components described in the story. |
@chakAs3 hello! Related storybook-vue/storybook-nuxt#4 |
Salam @Ibochkarev, please can you use the latest version of @storybook-vue/nuxt recently published, it may fix your issue inshallah |
@Ibochkarev I am having the same problem ' ERROR Internal server error: At least one or <script> is required in a single file component. Did you find a fix for this? |
@rpowersstl Try upgrading to the latest non-stable version. It should partially correct this error |
I tried using Can you tell me the version that you are using? Thank you. |
@nearking try
|
@chakAs3 Good afternoon Unfortunately, the error did not go away in the last alpha. The vue file for which there is no story is scanned. And everything falls on it. I am ready to more actively test solutions on your part in order to close this bug. |
@chakAs3 Good afternoon Are there any changes in this matter? Is there anything to test/change in the settings? |
Describe the bug
When using use methods from
useNuxtApp().$app.filters
storybook and vitest gives errors when usingTo Reproduce
When using use methods from
useNuxtApp().$app.filters
storybook and vitest gives errors when usinga-avatar.stories.js
a-avatar.vue
System
Additional context
The text was updated successfully, but these errors were encountered: