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

DefinePlugin: "Conflicting values for 'process.env'" if you have a .env file #15927

Closed
jdelStrother opened this issue Aug 27, 2021 · 2 comments
Closed

Comments

@jdelStrother
Copy link

Describe the bug
If you have a .env file present in the cwd, it causes a warning to be emitted:

WARNING in DefinePlugin
Conflicting values for 'process.env'

To Reproduce
Checkout https://github.com/jdelStrother/conflicting-process-env
Run yarn
Run yarn start-storybook --smoke-test

System

Environment Info:

  System:
    OS: macOS 11.5.2
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 16.2.0 - ~/.nix-profile/bin/node
    Yarn: 1.22.10 - ~/.nix-profile/bin/yarn
    npm: 7.13.0 - ~/.nix-profile/bin/npm
  npmPackages:
    @storybook/addon-actions: ^6.3.7 => 6.3.7
    @storybook/addon-essentials: ^6.3.7 => 6.3.7
    @storybook/addon-links: ^6.3.7 => 6.3.7
    @storybook/addon-storyshots: ^6.3.7 => 6.3.7
    @storybook/builder-webpack5: ^6.3.7 => 6.3.7
    @storybook/core: ^6.3.7 => 6.3.7
    @storybook/manager-webpack5: ^6.3.7 => 6.3.7
    @storybook/react: ^6.3.7 => 6.3.7
    @storybook/theming: ^6.3.7 => 6.3.7

Additional context

When running storybook interactively, one can just ignore this warning. However, it does cause start-storybook --smoke-test to fail, which is annoying for CI purposes. I don't actually want my .env file loaded in storybook, but can't see a good way of preventing the automatic detection.

@usrrname
Copy link
Contributor

usrrname commented Aug 27, 2021

Hey jdelStrother, thanks for filing this issue! I think adding the webpack5 tag too to bring it to the core team's attention.

I've been experiencing the same issue while using sb@6.3.7 with node 14.17.0
Also looked at #14257 and used these suggested resolutions in my package.json to get it running locally.

Environment Info:

  System:
    OS: macOS 11.5.2
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
  Browsers:
    Chrome: 92.0.4515.159
    Safari: 14.1.2
  npmPackages:
    @storybook/addon-a11y: ^6.3.7 => 6.3.7 
    @storybook/addon-actions: ^6.3.7 => 6.3.7 
    @storybook/addon-docs: ^6.3.7 => 6.3.7 
    @storybook/addon-essentials: ^6.3.7 => 6.3.7 
    @storybook/addon-jest: ^6.3.7 => 6.3.7 
    @storybook/addon-links: ^6.3.7 => 6.3.7 
    @storybook/addon-storyshots: ^6.3.7 => 6.3.7 
    @storybook/addon-storyshots-puppeteer: ^6.3.7 => 6.3.7 
    @storybook/addon-viewport: ^6.3.7 => 6.3.7 
    @storybook/builder-webpack5: ^6.3.7 => 6.3.7 
    @storybook/manager-webpack5: ^6.3.7 => 6.3.7 
    @storybook/react: ^6.3.7 => 6.3.7 
    @storybook/testing-react: 0.0.22 => 0.0.22 
    @storybook/theming: ^6.3.7 => 6.3.7 

main.ts:

import path from 'path';
import 'dotenv';
import { BabelConfig } from 'ts-jest/dist/types';

module.exports = {
  stories: ['../src/**/*.stories.@(jsx|tsx|mdx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-docs',
    'storybook-addon-designs', // https://storybook.js.org/addons/storybook-addon-designs
    '@storybook/addon-essentials',
    '@storybook/addon-jest',
    '@storybook/addon-storyshots',
    '@storybook/addon-a11y',
    '@storybook/addon-viewport/register',
    'storybook-addon-gatsby',
  ],
  core: {
    builder: 'webpack5',
  },
  typescript: {
    check: true,
  },
  babel: async (options: BabelConfig) => {
    return {
      ...options,
    };
  },
  webpackFinal: async (config: any) => {
    config.module.rules[0].exclude = [/node_modules\/(?!(gatsby)\/)/];

    config.output = {
      path: path.join(__dirname, '../dist'),
      publicPath: '/',
      filename: 'static/js/[name].js',
      chunkFilename: 'static/js/[name].chunk.js',
    };

    config.resolve.fallback = {
      crypto: false,
      path: require.resolve('path-browserify'),
      assert: require.resolve('assert-browserify'),
    };

    // Return the altered config
    return config;
  },
};

I did also notice that a local dev with start-storybook "completes" at 99%... ( ͡° ʖ̯ ͡°)

@shilman
Copy link
Member

shilman commented Sep 7, 2021

Ta-da!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.4.0-alpha.34 containing PR #15925 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants