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

util should be added to dependencies #3501

Closed
appzuka opened this issue Oct 18, 2020 · 20 comments
Closed

util should be added to dependencies #3501

appzuka opened this issue Oct 18, 2020 · 20 comments
Labels
bug This issue is a bug.

Comments

@appzuka
Copy link

appzuka commented Oct 18, 2020

util is a dependency of the library but is not listed in package.json. For example, it is in event_listeners.js:

var params = require('util').inspect(censoredParams, true, null);

Building with webpack v4 this was not an issue as util was also a dependency of webpack. In webpack v5 util is no longer a dependency so builds will fail unless it is included by other modules.

@appzuka appzuka added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 18, 2020
@yaquawa
Copy link

yaquawa commented Nov 12, 2020

same issue here.

@trivikr
Copy link
Member

trivikr commented Nov 12, 2020

Building with webpack v4 this was not an issue as util was also a dependency of webpack. In webpack v5 util is no longer a dependency so builds will fail unless it is included by other modules.

@appzuka / @yaquawa Can you provide an example code where there is a build failure in webpack5?

@appzuka
Copy link
Author

appzuka commented Nov 12, 2020

@trivikr,

Here is a tiny repo that demonstrates the issue:

https://github.com/appzuka/webpack5-aws-sdk

There was no issue with webpack4 because util was a dependency of webpack4.

@ajredniwja
Copy link
Member

Hey @appzuka thanks for putting up that repo, I ran the code but I didn't see any errors just warnings

Info
➜  webpack5-aws-sdk git:(master) yarn build
yarn run v1.22.5
warning package.json: No license field
warning ../../../../../package.json: No license field
$ webpack --mode production
[webpack-cli] Compilation finished
asset main.js 2.66 MiB [emitted] [minimized] [big] (name: main) 1 related asset
runtime modules 1000 bytes 5 modules
modules by path ./node_modules/aws-sdk/ 2.93 MiB
  json modules 2.37 MiB 231 modules
  javascript modules 572 KiB 175 modules
modules by path ../../node_modules/ 50.8 KiB 11 modules
modules by path ./node_modules/uuid/ 6.05 KiB
  modules by path ./node_modules/uuid/*.js 4.04 KiB 3 modules
  modules by path ./node_modules/uuid/lib/*.js 2.01 KiB 2 modules
modules by path ./node_modules/querystring/*.js 4.51 KiB 3 modules
modules by path ./node_modules/buffer/ 49.6 KiB
  ./node_modules/buffer/index.js 47.5 KiB [built] [code generated]
  ./node_modules/buffer/node_modules/ieee754/index.js 2.1 KiB [built] [code generated]
8 modules

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
  main.js (2.66 MiB)

WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
  main (2.66 MiB)
      main.js


WARNING in webpack performance recommendations:
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
For more info visit https://webpack.js.org/guides/code-splitting/

webpack 5.4.0 compiled with 3 warnings in 5977 ms
✨  Done in 7.26s.

Can I get more informati0on on what error you see?

@ajredniwja ajredniwja added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 19, 2020
@appzuka
Copy link
Author

appzuka commented Nov 19, 2020

HI @ajredniwja, Thanks for taking a look. Here is the error I see when I run yarn build

ERROR in ./node_modules/aws-sdk/lib/event_listeners.js 572:21-44
Module not found: Error: Can't resolve 'util' in 'C:\Users\nick\code\scratch\webpated]ck5-aws-sdk\node_modules\aws-sdk\lib'
Click to see the full output:
yarn run v1.22.4
warning package.json: No license field
$ webpack --mode production
[webpack-cli] Compilation finished
assets by status 2.64 MiB [cached] 1 asset
runtime modules 1000 bytes 5 modules
modules by path ./node_modules/aws-sdk/ 2.93 MiB
  json modules 2.37 MiB 231 modules
  javascript modules 572 KiB 175 modules
modules by path ./node_modules/uuid/ 6.05 KiB
  ./node_modules/querystring/encode.js 2.04 KiB [built] [code generated]
modules by path ./node_modules/buffer/ 49.6 KiB
  ./node_modules/buffer/index.js 47.5 KiB [built] [code generated]
  ./node_modules/buffer/node_modules/ieee754/index.js 2.1 KiB [built] [code generated]
8 modules

ERROR in ./node_modules/aws-sdk/lib/event_listeners.js 572:21-44
Module not found: Error: Can't resolve 'util' in 'C:\Users\nick\code\scratch\webpated]ck5-aws-sdk\node_modules\aws-sdk\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.                                                                         ck5-aws-sdk\node_modules\aws-sdk\lib'
This is no longer the case. Verify if you need this module and configure a polyfill for it.                                                                          default.
                                                                                  l for it.
If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }' 
        - install 'util'
If you don't want to include a polyfill, you can use an empty module like this:   
        resolve.fallback: { "util": false }
 @ ./node_modules/aws-sdk/lib/core.js 82:0-28
 @ ./node_modules/aws-sdk/lib/browser.js 3:10-27
 @ ./src/index.js 1:0-26

webpack 5.4.0 compiled with 1 error in 7777 ms

If you check the line with the error you will see that the code does indeed depend on the util package:

var params = require('util').inspect(censoredParams, true, null);

If I manually add util by yarn add util and then yarn build the error disappears and I get the same output as you. Are you adding the util package somehow? Is it in the node_modules directory after yarn install.

aws-sdk clearly uses util so I believe it should be listed as a dependency in package.json.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 20, 2020
@ajredniwja
Copy link
Member

I am not adding the package. Can run more tests.

@alexander-akait
Copy link

Workaround for webpack@5:

npm i util

webpack.config.js

module.exports = {
  // Other options...
  resolve: {
    fallback: { 
      "util": require.resolve("util/"),
    },
  }
}

@appzuka
Copy link
Author

appzuka commented Jan 13, 2021

I believe the only workaround necessary is to install util. You should not also need the resolve-fallback.

I'm not sure why util has not been added as a dependency. It is clearly used by aws-sdk-js so it should be there. The issue was masked because util was a dependency of webpack4 but it was been removed in webpack 5, which is why this is now an issue.

@rlejeune
Copy link

rlejeune commented Aug 11, 2021

@ajredniwja I am not adding the package. Can run more tests.

With Node 14 you'll have the error

@ntishkevich
Copy link

Curious about the progress of this issue. Are there any PRs with fixes or updates? The issue was created almost a year ago and still hasn't been fixed.

@rnewman
Copy link

rnewman commented Oct 13, 2021

This is still broken.

@jonathaneemmett
Copy link

Still an issue as of Feb 1, 2022

@cvrchinmay
Copy link

Still an issue as of Mar 15,2022

@gaulatti
Copy link

gaulatti commented Apr 9, 2022

Still an issue as of Apr 9, 2022

@itowk
Copy link

itowk commented May 2, 2022

Still an issue as of May 2, 2022

@tamascsaba
Copy link

Still an issue as of May 4, 2022

@AlouiLouai
Copy link

Still an issue as of May 6, 2022

@wcheek
Copy link

wcheek commented Jun 20, 2022

Still an issue as of June 20, 2022

@valueduser valueduser mentioned this issue Jul 5, 2022
2 tasks
@tareq0065
Copy link

Workaround for webpack@5:

npm i util

webpack.config.js

module.exports = {
  // Other options...
  resolve: {
    fallback: { 
      "util": require.resolve("util/"),
    },
  }
}

this solution works good

@trivikr
Copy link
Member

trivikr commented Jul 17, 2022

Fixed in #4148 which was released in v2.1174.0

@trivikr trivikr closed this as completed Jul 17, 2022
@ajredniwja ajredniwja mentioned this issue Sep 16, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests