node-libs-browser icon indicating copy to clipboard operation
node-libs-browser copied to clipboard

Module not found: Can't resolve 'util'

Open navono opened this issue 5 years ago • 2 comments

Description

I create a app with create-react-app with --typescript, and add some lib to it. But when I execute start script, a compilation error has occurred:

Failed to compile.

./node_modules/browserify-zlib/lib/index.js
Module not found: Can't resolve 'util' in 'E:\sourcecode\frontend\AppDev-web\node_modules\browserify-zlib\lib'

I'm not explicit import browserify-zlib, so I search it in project, in yarn.lock file, I found this:

node-libs-browser@^2.0.0:
  version "2.2.0"
  resolved "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.0.tgz#c72f60d9d46de08a940dedbb25f3ffa2f9bbaa77"
  integrity sha512-5MQunG/oyOaBdttrL40dA7bUfPORLRWMUJLQtMg7nluxUvk5XwnLdL9twQHFAjRx/y7mIMkLKT9++qPbbk6BZA==
  dependencies:
    assert "^1.1.1"
    browserify-zlib "^0.2.0"
    buffer "^4.3.0"
    console-browserify "^1.1.0"
    constants-browserify "^1.0.0"
    crypto-browserify "^3.11.0"
    domain-browser "^1.1.1"
    events "^3.0.0"
    https-browserify "^1.0.0"
    os-browserify "^0.3.0"
    path-browserify "0.0.0"
    process "^0.11.10"
    punycode "^1.2.4"
    querystring-es3 "^0.2.0"
    readable-stream "^2.3.3"
    stream-browserify "^2.0.1"
    stream-http "^2.7.2"
    string_decoder "^1.0.0"
    timers-browserify "^2.0.4"
    tty-browserify "0.0.0"
    url "^0.11.0"
    util "^0.11.0"
    vm-browserify "0.0.4"
  • [x] I tried add util package, still not work
  • [x] I tried add util in webpack.config.js like this:
    node: {
      util: 'empty',
      module: 'empty',
      dgram: 'empty',
      dns: 'mock',
      fs: 'empty',
      net: 'empty',
      tls: 'empty',
      child_process: 'empty',
    },

still not work

Info

create-react-app: version: 2.1.8 webpack.config.js package.json tsconfig.json

Anybody know anything about this?

navono avatar Apr 15 '19 08:04 navono

I'm also having this error with Angular, was there any solution?

sbasehart avatar Feb 21 '20 18:02 sbasehart

it's too long after I commit this issue, and totally foget how to resolve this error.

navono avatar Feb 24 '20 05:02 navono