storybook: Storybook with builder-webpac5 complains about conflicting values in DefinePlugin and not redefine custom variables

Describe the bug I am using Storybook6-rc01 with builder-webpack5. I define several variables with patching webpack config and DefinePlugin through function webpackFinal:

plugins: [
      new webpack.DefinePlugin({
      "process.env.NODE_ENV": JSON.stringify("development"),
      "window.FAKE_GLOBAL_FUNCTION": "(function() { return false; })",
    }),
],

Function FAKE_GLOBAL_FUNCTION call is added to test story

But there is error about Conflicting values for 'process.env' in build console and there is error on rendered story on UI about window.FAKE_GLOBAL_FUNCTION is not defined

To Reproduce Steps to reproduce the behavior:

  1. Go to https://github.com/khats/storybook-demo
  2. Pull project
  3. Install dependencies with yarn
  4. Start storybook with yarn start-storybook

Expected behavior

  1. No error in build console: Conflicting values for 'process.env' '{NODE_ENV: "development", NODE_PATH: [], STORYBOOK: "true", PUBLIC_URL: "."}' !== '{}'
  2. window. FAKE_GLOBAL_FUNCTION is defined and story is rendered without error

Screenshots

image

image

Code snippets If applicable, add code samples to help explain your problem.

System Environment Info:

System: OS: macOS 11.0.1 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Binaries: Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node Yarn: 2.4.0 - /usr/local/bin/yarn npm: 6.14.9 - ~/.nvm/versions/node/v14.15.3/bin/npm Browsers: Chrome: 89.0.4389.90 Firefox: 76.0.1 Safari: 14.0.1

Additional context Add any other context about the problem here.

┆Issue is synchronized with this Asana task by Unito

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 21
  • Comments: 61 (14 by maintainers)

Most upvoted comments

Storybook v6.5.12 Angular v14.2.2

I’m seeing this warning as well, but SB seems to run fine.

WARNING in DefinePlugin
Conflicting values for 'process.env.NODE_ENV'

1 WARNING in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)

1 warning has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

manager (webpack 5.74.0) compiled with 2 warnings in 88502 ms
  1. I have webpack5 installed as a dev dependency in the workspace.
  2. My workspace contains an Angular component library and a test app.
  3. The test app has environment files.
  4. The component library is the default project.
  5. I have Storybook configured in angular.json.

Hi, any update regarding this issue? Storybook version: 6.5.9 I am using Angular 13 with @storybook/angular and @storybook/builder-webpack5 without any manually added plugin, but how should I fix it? Thanks.

hi @khats thanks for the quick response, I’m talking about this issue

Screenshot 2021-12-23 at 13 24 44

Also the build is stuck at 99%

Still seeing “Conflicting values for process.env” 😞 . Upgraded from 6.2.9 to 6.3.4:

image

Great Caesar’s ghost!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.1 containing PR #15365 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb upgrade

@WalterWeidner since I’m using storybook with angular, all of them stand out for me 😅

Hey guys, I was able to overcome the build warning issue with the solution from this thread: https://github.com/storybookjs/storybook/issues/6763#issuecomment-491415516

Like this:

config.plugins = [
  ...config.plugins.filter((plugin) => !plugin.definitions),
  new webpack.DefinePlugin({
    "process.env.NODE_ENV": JSON.stringify(
      configType === "DEVELOPMENT" ? "development" : "production"
    ),
    "process.env.NODE_PATH": JSON.stringify([]),
    "process.env.STORYBOOK": JSON.stringify('true'),
    "process.env.PUBLIC_PATH": JSON.stringify("."),
  })
];

💪

We’re seeing this error with 6.3.6.

Also looking for work around for this issue.

Hey everyone, is there any temporary work around for this issue?

I have the same issue as well, Storybook works nonetheless, but the live reload is not working when doing edits to components. I need to manually refresh the Storybook webpage in order to see my changes.

confirming for 6.3.10 and 6.3.12

I still see this warning with Storybook 6.3.8. (node 14.17.6)

Seeing this error with Storybook 6.3.7. I’m using node 14.17.0

additionally when running build-storybook the task gets stuck and never finish, even though the files are created in storybook-static folder

Removing the yarn resolutions removed the error on build-storybook and storybook however I am still having an issue with process not being defined

@shilman i have updated original linked project to 6.3-beta.10

we are running into this issue as well when using yarn resolutions for webpack 5 in our workspaces monorepo