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]: sb7+vite env variables not working inside addons #20675

Closed
Luk-z opened this issue Jan 18, 2023 · 9 comments
Closed

[Bug]: sb7+vite env variables not working inside addons #20675

Luk-z opened this issue Jan 18, 2023 · 9 comments

Comments

@Luk-z
Copy link
Contributor

Luk-z commented Jan 18, 2023

Describe the bug

Environment variables are not available inside addon.

This is a repo to reproduce the error: node16 + sb7 + vite + npm
https://github.com/Luk-z/vite_ts_sb7_npm

This is a repo where the env variables works inside addons: node14 + sb6 + vite + npm
https://github.com/Luk-z/vite_ts_sb6_npm

To write the simple addon i followed https://storybook.js.org/docs/react/addons/writing-addons.

I'm expecting env variables are available inside an addon.

To Reproduce

https://github.com/Luk-z/vite_ts_sb7_npm

System

$ npx sb@next info

Environment Info:

  System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.1/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.0/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Firefox: 106.0.1
    Safari: 16.0
  npmPackages:
    @storybook/addon-essentials: ^7.0.0-beta.30 => 7.0.0-beta.30 
    @storybook/addon-interactions: ^7.0.0-beta.30 => 7.0.0-beta.30 
    @storybook/addon-links: ^7.0.0-beta.30 => 7.0.0-beta.30 
    @storybook/blocks: ^7.0.0-beta.30 => 7.0.0-beta.30 
    @storybook/react: ^7.0.0-beta.30 => 7.0.0-beta.30 
    @storybook/react-vite: ^7.0.0-beta.30 => 7.0.0-beta.30 
    @storybook/testing-library: ^0.0.13 => 0.0.13

Additional context

No response

@IanVS
Copy link
Member

IanVS commented Jan 25, 2023

Where are you setting the STORYBOOK_TEST env var?

@Luk-z
Copy link
Contributor Author

Luk-z commented Jan 25, 2023

@IanVS
Copy link
Member

IanVS commented Jan 25, 2023

I think this isn't related to Vite, since it's an addon and being rendered in the manager. @ndelangen is this maybe a consequence of changing the manager over from Webpack to esbuild? I see that process.env is an empty object even when prepending to the storybook command (STORYBOOK_TEST=abcd storybook dev -p 6006), so it doesn't seem related to loading the .env file.

@ndelangen
Copy link
Member

Right.. so the builder-manager needs to be modified to setup injecting environment variables into addons-bundles.

Likely to be implemented here:

aliasPlugin({
process: require.resolve('process/browser.js'),
util: require.resolve('util/util.js'),
assert: require.resolve('browser-assert'),
}),
globalExternals(definitions),
pnpPlugin(),

@ndelangen ndelangen moved this to In Progress in Core Team Projects Jan 30, 2023
ndelangen added a commit that referenced this issue Jan 31, 2023
fix #20675 by adding an esbuild plugin to inject env variables
@github-project-automation github-project-automation bot moved this from In Progress to Done in Core Team Projects Jan 31, 2023
@IanVS
Copy link
Member

IanVS commented Jan 31, 2023

Not released yet, was closed accidentally from PR title.

@IanVS IanVS reopened this Jan 31, 2023
@ndelangen
Copy link
Member

@IanVS @vanessayuenn @shilman we're using the auto close feature nowadays, correct?

@shilman
Copy link
Member

shilman commented Feb 1, 2023

Yes. @IanVS We're experimenting with using GH's PR-issue linkage feature so that our workflow is more standard

@shilman
Copy link
Member

shilman commented Feb 1, 2023

Crikey!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.39 containing PR #20834 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

@Luk-z
Copy link
Contributor Author

Luk-z commented Feb 2, 2023

It works, thx!

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

4 participants