Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

Webpack adds the nodejs shims when they actually not necessary. #194

Closed

Description

@mightyaleksey

Do you want to request a feature or report a bug?

I think it's a bug (not sure).

What is the current behavior?

Webpack includes in the resulting bundle nodejs shims for buffer, process and path modules when they are actually not necessary. It adds about 30kb in the minified bundle.
I faced this issue after updating version of webpack from 1.x to 2.x.

If the current behavior is a bug, please provide the steps to reproduce.

I made a small example, which illustrates the problem: https://github.com/sullenor/webpack-shims and attached the stats files:

What is the expected behavior?

Expected the resulting bundle to have a smaller size: ~3-5kb, not 33kb (minimized).

If this is a feature request, what is motivation or use case for changing the behavior?

No

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

macOs Sierra 10.12.3, nodejs v7.7.2, webpack v2.2.1,
https://github.com/sullenor/webpack-shims/blob/master/package.json#L3-L6

From webpack/webpack#4473

Activity

  1. michael-ciniawsky commented on Mar 16, 2017

    @michael-ciniawsky
    Contributor

    @sullenor We need to investigate but not sure if we can fix it easily, as a workaround could you try

    webpack.config.js

    module.exports = {
    ...
    node: {
      buffer: false
      ...
      }
    }

    I know it's inconvenient and shouldn't be a requirement to use style-loader or any other loader, but for the meantime 😛

  2. mightyaleksey commented on Mar 17, 2017

    @mightyaleksey
    Author

    @michael-ciniawsky looks like I came to the similar workaround :)

    thank you!

  3. ablankenship10 commented on May 1, 2017

    @ablankenship10

    Think I am having a similar but slightly different issue. Without style-loader the webpack output:

    Version: webpack 2.4.1
    Time: 79ms
        Asset     Size  Chunks             Chunk Names
    bundle.js  2.74 kB       0  [emitted]  main
       [0] ./src/main.js 0 bytes {0} [built]
       [1] ./index.js 26 bytes {0} [built]
    
    

    Importing 1 empty stylesheet into my project causes this:

    Version: webpack 2.4.1
    Time: 372ms
        Asset     Size  Chunks             Chunk Names
    bundle.js  73.5 kB       0  [emitted]  main
       [0] ./src/main.js 33 bytes {0} [built]
       [1] ./index.js 26 bytes {0} [built]
       [2] ./~/base64-js/index.js 3.48 kB {0} [built]
       [3] ./~/buffer/index.js 48.6 kB {0} [built]
       [4] ./~/css-loader!./src/style.css 199 bytes {0} [built]
       [5] ./~/css-loader/lib/css-base.js 2.19 kB {0} [built]
       [6] ./~/ieee754/index.js 2.05 kB {0} [built]
       [7] ./~/isarray/index.js 132 bytes {0} [built]
       [8] ./~/style-loader/addStyles.js 8.51 kB {0} [built]
       [9] ./~/style-loader/fixUrls.js 3.01 kB {0} [built]
      [10] ./src/style.css 899 bytes {0} [built]
      [11] (webpack)/buildin/global.js 509 bytes {0} [built]
    

    My webpack config with the work around mentioned above:

    module.exports = {
      entry: './index.js',
      output: {
        filename: 'bundle.js'
      },
      node: {
        buffer: false
      },
      module: {
        loaders: [
          {test: /\.html$/, loader: "html-loader"},
          {test: /\.less$/, loader: 'style-loader!css-loader!less-loader'},
          {test: /\.css$/, loader: 'style-loader!css-loader'},
        ]
      }
    };
    
    

    EDIT: It looks like the problem is actually with css-loader, not style-loader, and the work around should be Buffer with a capital B not lowercase.

    Issue Ref from webpack/css-loader#454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions