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

Webpack 5 SideEffectsFlagPlugin fails in production mode #275

Closed
Enase opened this issue Nov 12, 2020 · 5 comments
Closed

Webpack 5 SideEffectsFlagPlugin fails in production mode #275

Enase opened this issue Nov 12, 2020 · 5 comments

Comments

@Enase
Copy link

Enase commented Nov 12, 2020

In some reason I get the Type error in production mode only.

TypeError: dep.getModuleEvaluationSideEffectsState is not a function
    at NormalModule.getSideEffectsConnectionState (/{some_path}/node_modules/webpack-cli/node_modules/webpack/lib/NormalModule.js:879:23)
    at HarmonyImportSideEffectDependency.getModuleEvaluationSideEffectsState (/{some_path}/node_modules/webpack-cli/node_modules/webpack/lib/dependencies/HarmonyImportSideEffectDependency.js:50:20)
    at NormalModule.getSideEffectsConnectionState (/{some_path}/node_modules/webpack-cli/node_modules/webpack/lib/NormalModule.js:879:23)
    at /{some_path}/node_modules/webpack-cli/node_modules/webpack/lib/optimize/SideEffectsFlagPlugin.js:229:18
    at Hook.eval [as call] (eval at create (/{some_path}/node_modules/webpack-cli/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:10:16)
    at Hook.CALL_DELEGATE [as _call] (/{some_path}/node_modules/webpack-cli/node_modules/tapable/lib/Hook.js:14:14)

console.log of dep variable in my case:

ConstDependency {
  module: null,
  weak: false,
  optional: false,
  loc: SourceLocation {
    start: Position { line: 16, column: 25 },
    end: Position { line: 16, column: 36 }
  },
  expression: '{}',
  range: [ 594, 605 ],
  requireWebpackRequire: false
}

webpack config

const dotenv = require('dotenv');
const path = require('path');
const Dotenv = require('dotenv-webpack');
const pkg = require('../package.json');

const mode = process.env.WEBPACK_ENV || 'development';
const libraryName = pkg.name;

const envFile = path.join(__dirname, mode === 'production' ? '.env.prod' : '.env.dev');

module.exports = {
  mode,
  entry: {
    loader: path.join(__dirname, 'src', 'loader.js'),
  },
  devtool: mode === 'production' ? 'source-map' : 'inline-source-map',
  output: {
    library: libraryName,
    libraryTarget: 'umd',
    filename: `[name]${mode === 'production' ? '.min' : ''}.js`,
    path: path.join(__dirname, 'dist'),
    umdNamedDefine: true,
    globalObject: "typeof self !== 'undefined' ? self : this",
  },
  optimization: {
    minimize: mode === 'production',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /(node_modules|bower_components)/,
      },
      {
        test: /\.(html|css|txt)$/,
        use: 'raw-loader',
      },
    ],
  },
  plugins: [
    new Dotenv({
      defaults: path.join(__dirname, '.env.defaults'),
      path: envFile,
      systemvars: true,
      safe: path.resolve(__dirname, '.env.example'),
      silent: false,
    }),
  ],
};

If I set it off - everything works fine

  optimization: {
    minimize: mode === 'production',
    sideEffects: false
  },
@mrsteele
Copy link
Owner

@Enase Taking off this plugin resolves that bug?

@Enase
Copy link
Author

Enase commented Nov 16, 2020

@mrsteele yes it is

@mrsteele
Copy link
Owner

you also removed sideEffects, did that make a difference turning on and off? I don't see this report from anyone else. Also, you included dotenv which is not needed in your require above.

@Enase
Copy link
Author

Enase commented Nov 16, 2020

@mrsteele I'll try to provide more details or example repo.

@katorres02
Copy link

I had a similar error, in my case this was the solution https://giters.com/storybookjs/storybook/issues/15221

const { environment } = require("@rails/webpacker");

const customConfig = {
  //
  //
  //
  optimization: {
    sideEffects: false
  }
};

environment.config.merge(customConfig);

module.exports = environment;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants