title: Rails 6.1.0 [webpack-cli] TypeError: Cannot read property 'plugins' of undefined
body: <p>My Rails+Webpack app contanizered with Docker worked fine in 6.0.3.4 and with</p>
  <pre><code>&quot;webpack&quot;: &quot;^4.44.1&quot;,
  &quot;webpack-cli&quot;: &quot;^3.3.9&quot;
  </code></pre>
  <p>After upgrade to 6.1.0 <strong>webpack-cli</strong> cannot read property 'plugins' (or 'config' or 'loaders') in the <em>environment.js</em> during <code>assets:precompile</code>.</p>
  <pre><code>...Step 20/22 : RUN bundle exec rake RAILS_ENV=staging assets:precompile
   ---&gt; Running in bca898bb9014
  yarn install v1.22.5
  warning package.json: No license field
  warning No license field
  [1/4] Resolving packages...
  [2/4] Fetching packages...
  info fsevents@1.2.13: The platform &quot;linux&quot; is incompatible with this module.
  info &quot;fsevents@1.2.13&quot; is an optional dependency and failed compatibility check. Excluding it from installation.
  [3/4] Linking dependencies...
  warning &quot; &gt; tempusdominus-bootstrap-4@5.39.0&quot; has unmet peer dependency &quot;moment@^2.29.0&quot;.
  warning &quot; &gt; tempusdominus-bootstrap-4@5.39.0&quot; has unmet peer dependency &quot;moment-timezone@^0.5.31&quot;.
  warning &quot; &gt; tempusdominus-bootstrap-4@5.39.0&quot; has unmet peer dependency &quot;tempusdominus-core@5.19.0&quot;.
  warning &quot;webpack-dev-server &gt; webpack-dev-middleware@3.7.2&quot; has incorrect peer dependency &quot;webpack@^4.0.0&quot;.
  [4/4] Building fresh packages...
  Done in 4.28s.
  I, [2021-01-10T14:31:28.268903 #7]  INFO -- : Writing /var/www/&lt;RoR-app&gt;/public/assets/manifest-a72913f4c604bc8f97dd576fc8777bf029401f6af0e14b6a6c9d3874acfe73e4.js
  I, [2021-01-10T14:31:28.269857 #7]  INFO -- : Writing /var/www/&lt;RoR-app&gt;/public/assets/manifest-a72913f4c604bc8f97dd576fc8777bf029401f6af0e14b6a6c9d3874acfe73e4.js.gz
  Compiling...
  Compilation failed:
  warning package.json: No license field
  [webpack-cli] Failed to load '/var/www/&lt;RoR-app&gt;/config/webpack/production.js'
  [webpack-cli] TypeError: Cannot read property 'plugins' of undefined
      at Object.&lt;anonymous&gt; (/var/www/&lt;RoR-app&gt;/config/webpack/environment.js:7:13)
      at Module._compile (/var/www/&lt;RoR-app&gt;/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
      at Module.load (internal/modules/cjs/loader.js:928:32)
      at Function.Module._load (internal/modules/cjs/loader.js:769:14)
      at Module.require (internal/modules/cjs/loader.js:952:19)
      at require (/var/www/&lt;RoR-app&gt;/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
      at Object.&lt;anonymous&gt; (/var/www/&lt;RoR-app&gt;/config/webpack/production.js:3:21)
      at Module._compile (/var/www/&lt;RoR-app&gt;/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
  
  ERROR: Service 'ruby' failed to build: The command '/bin/sh -c bundle exec rake RAILS_ENV=staging assets:precompile' returned a non-zero code: 1
  </code></pre>
  <p><strong>config/webpack/production.js</strong></p>
  <pre><code>process.env.NODE_ENV = process.env.NODE_ENV || 'production'
  const environment = require('./environment')
  module.exports = environment.toWebpackConfig()
  </code></pre>
  <p><strong>config/webpack/environment.js</strong></p>
  <pre><code>const { environment } = require('@rails/webpacker');
      const webpack = require('webpack');
      const expose = require('./loaders/expose');
      const coffee = require('./loaders/coffee');
      const erb = require('./loaders/erb');
      
      environment.plugins.prepend('Provide',
        new webpack.ProvidePlugin({
          $: 'jquery',
          jQuery: 'jquery',
          jquery: 'jquery',
          Popper: ['popper.js', 'default'],
          Rails: ['@rails/ujs'],
          moment: 'moment'
        })
      );
      ...
  </code></pre>
  <p><strong>package.json</strong></p>
  <pre><code>{
    &quot;dependencies&quot;: {
      &quot;@rails/ujs&quot;: &quot;^6.1.1&quot;,
      &quot;@rails/webpacker&quot;: &quot;^6.0.0-pre.1&quot;,
      &quot;bloodhound-js&quot;: &quot;^1.2.3&quot;,
      &quot;bootstrap&quot;: &quot;^4.5.3&quot;,
      &quot;clean-webpack-plugin&quot;: &quot;^3.0.0&quot;,
      &quot;cocoon&quot;: &quot;github:nathanvda/cocoon#c24ba53&quot;,
      &quot;core-js&quot;: &quot;^3.8.2&quot;,
      &quot;css-loader&quot;: &quot;^5.0.1&quot;,
      &quot;exports-loader&quot;: &quot;^1.1.1&quot;,
      &quot;expose-loader&quot;: &quot;^1.0.3&quot;,
      &quot;file-loader&quot;: &quot;^6.2.0&quot;,
      &quot;font-awesome&quot;: &quot;^4.7.0&quot;,
      &quot;jbuilder&quot;: &quot;^0.0.5&quot;,
      &quot;jquery&quot;: &quot;^3.5.1&quot;,
      &quot;jquery-ui&quot;: &quot;^1.12.1&quot;,
      &quot;jquery-ui-dist&quot;: &quot;^1.12.1&quot;,
      &quot;jquery-ujs&quot;: &quot;^1.2.2&quot;,
      &quot;jstree&quot;: &quot;^3.3.11&quot;,
      &quot;popper.js&quot;: &quot;^1.16.1&quot;,
      &quot;sidekiq&quot;: &quot;^1.1.1&quot;,
      &quot;tempusdominus-bootstrap-4&quot;: &quot;^5.39.0&quot;,
      &quot;turbolinks&quot;: &quot;^5.2.0&quot;,
      &quot;webpack&quot;: &quot;^5.12.2&quot;,
      &quot;webpack-cli&quot;: &quot;^4.3.1&quot;,
      &quot;webpack-dev-middleware&quot;: &quot;^4.0.2&quot;,
      &quot;webpack-dev-server&quot;: &quot;^3.11.1&quot;
    },
    &quot;devDependencies&quot;: {}
  }
  </code></pre>