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

[Bug]: TypeError (undefined global) when using setup() with vue3-vite #25400

Closed
MacroMan opened this issue Jan 2, 2024 · 11 comments
Closed

[Bug]: TypeError (undefined global) when using setup() with vue3-vite #25400

MacroMan opened this issue Jan 2, 2024 · 11 comments
Assignees
Milestone

Comments

@MacroMan
Copy link

MacroMan commented Jan 2, 2024

Describe the bug

When using setup() from @storybook/vue3 in .storybook/main.ts:

import type { StorybookConfig } from "@storybook/vue3-vite";
import { setup } from "@storybook/vue3"

setup((app): void => {
  // app.use(PrimeVue);
});

const config: StorybookConfig = {
  ...
};
export default config;

the following error is thrown:

> storybook dev -p 6006

@storybook/cli v7.6.4

TypeError: Cannot set properties of undefined (setting 'STORYBOOK_ENV')
    at Object.<anonymous> (/home/david/crowdhelix-projects/artemis/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@storybook/vue3/dist/index.js:26:28)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Object.newLoader (/home/david/crowdhelix-projects/artemis/node_modules/.pnpm/[email protected][email protected]/node_modules/esbuild-register/dist/node.js:2262:9)
    at extensions..js (/home/david/crowdhelix-projects/artemis/node_modules/.pnpm/[email protected][email protected]/node_modules/esbuild-register/dist/node.js:4838:24)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (./.storybook/main.ts:2:23)

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

 ELIFECYCLE  Command failed with exit code 1.

To Reproduce

https://stackblitz.com/edit/github-2zq7kx?file=.storybook%2Fmain.ts

System

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (16) x64 AMD Ryzen 7 5700G with Radeon Graphics
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.9.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.4 - /usr/local/bin/npm
    pnpm: 8.12.1 - ~/.local/share/pnpm/pnpm <----- active
  Browsers:
    Chrome: 120.0.6099.129
  npmPackages:
    @storybook/addon-essentials: ^7.6.4 => 7.6.4 
    @storybook/addon-interactions: ^7.6.4 => 7.6.4 
    @storybook/addon-links: ^7.6.4 => 7.6.4 
    @storybook/blocks: ^7.6.4 => 7.6.4 
    @storybook/test: ^7.6.4 => 7.6.4 
    @storybook/vue3: ^7.6.4 => 7.6.4 
    @storybook/vue3-vite: ^7.6.4 => 7.6.4 
    chromatic: ^10.1.0 => 10.1.0 
    storybook: ^7.6.4 => 7.6.4

Additional context

Tested and have same error with storybook 7.6.4, 7.6.7 and 8.0.0-alpha.6

@MacroMan
Copy link
Author

MacroMan commented Jan 2, 2024

I found some other issues with the same error:

@MacroMan
Copy link
Author

MacroMan commented Jan 2, 2024

I think the error originates from globals.ts, and looking at @storybook/global it seems that global from import { global } from '@storybook/global'; should always be set, so not really sure of the underlying cause

@shilman
Copy link
Member

shilman commented Jan 3, 2024

@ndelangen something is wrong with @storybook/global and it is manifesting itself in a variety of contexts. Prioritizing this issue since we have a repro available, but @dannyhw have also encountered something similar on his RN work recently.

@shilman shilman moved this to Empathy Backlog in Core Team Projects Jan 3, 2024
@ndelangen
Copy link
Member

@shilman @storybook/global didn't change.
Could it be that something upstream in the builder changed? vite?

@bodograumann

This comment was marked as off-topic.

@dannyhw
Copy link
Member

dannyhw commented Jan 4, 2024

Heres my comment about what I encountered for reference. Though I'm not sure its the same thing.

#25296 (comment)

My issue seems to come from the cjs bundling generating a dynamic require function in addon-actions. Looks like the cjs bundling is targetting node and so that might explain why it behaves differently.

In the issue here it looks like something in storybook vue maybe? though if you can resolve mjs instead maybe that fixes your issue.

@MacroMan
Copy link
Author

MacroMan commented Jan 4, 2024

@bodograumann I checked back to version 7.0.n and all exhibit the same error, so I suspect this is a downstream issue

@bodograumann
Copy link
Contributor

Thanks @MacroMan . I have hidden my comment as off-topic and will try to create a separate reproduction.

@vanessayuenn vanessayuenn added this to the 8.0-RC milestone Jan 9, 2024
@MacroMan
Copy link
Author

Is there any workaround that will let me add to the Vue instance without setup()? I just need to use Vue.use()

@vanessayuenn vanessayuenn moved this from Empathy Backlog to Empathy - Ready for work in Core Team Projects Feb 13, 2024
@vanessayuenn vanessayuenn modified the milestones: 8.0-RC, 8.0-Stable Feb 22, 2024
@vanessayuenn
Copy link
Contributor

@ndelangen by any chance is this fixed already since you changed the bundle target for tsup?

@ndelangen
Copy link
Member

ndelangen commented Mar 7, 2024

I'm looking at the repro, and AFAIK it makes not sense to be calling this in main.ts or is there?

import { setup } from "@storybook/vue3"

setup((app) => {
  // app.use(Plugin);
});

Should this code be located inside of preview.ts instead?
@MacroMan

I upgraded the repro and moved the code as described above and storybook started, no problem.

@ndelangen ndelangen moved this to In progress in Storybook 8.0 Roadmap Mar 7, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Storybook 8.0 Roadmap Mar 7, 2024
@github-project-automation github-project-automation bot moved this from Empathy - Ready for work to Done in Core Team Projects Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

7 participants