browserify: Error: Cannot find module 'node_modules/is-buffer/index.js' from ...

$ cat buf.js 
module.exports = function (b) { return Buffer.isBuffer(b) }
$ npm i browserify
...
$ ./node_modules/.bin/browserify buf.js 
Error: Cannot find module 'node_modules/is-buffer/index.js' from '/home/kirill/tmp'
    at /home/kirill/tmp/node_modules/resolve/lib/async.js:46:17
    at process (/home/kirill/tmp/node_modules/resolve/lib/async.js:173:43)
    at ondir (/home/kirill/tmp/node_modules/resolve/lib/async.js:188:17)
    at load (/home/kirill/tmp/node_modules/resolve/lib/async.js:69:43)
    at onex (/home/kirill/tmp/node_modules/resolve/lib/async.js:92:31)
    at /home/kirill/tmp/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)
$ vim buf.js
$ cat buf.js
;(function () { new Buffer(0) })()
module.exports = function (b) { return Buffer.isBuffer(b) }
$ ./node_modules/.bin/browserify buf.js 
(function e(t,n,r){function s(o, ... // ok

Related: https://github.com/substack/node-browserify/issues/1228

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 17 (2 by maintainers)

Commits related to this issue

Most upvoted comments

This should be fixed in insert-module-globals@7.0.2; do npm update to get it!

Just do this => npm install is-buffer --save

I just met this issue today and it turned out that using an alternative npm (cnpm) to be the culprit. cnpm handles modules folder differently with symlinks for faster installations, but it screws up the dynamic module resolving.

I am putting this info here because of the potential vulnerability of browserify when modules are managed differently.

@Zeeech Don’t use cnpm.