brunch / deppack

Extract node modules to browser.
MIT License
4 stars 13 forks source link

Improperly-cased require error when built-in modules shimmed #6

Closed garthk closed 8 years ago

garthk commented 8 years ago

I'm trying brunch on a legacy code base, and failing because:

30 Mar 04:29:27 - error: 

Resolving deps of node_modules/open/lib/open.js failed.
Improperly-cased require: 'child_process' in /tmp/test/node_modules/open/lib/open.js ; 

Resolving deps of node_modules/joi/lib/string.js failed.
Improperly-cased require: 'net' in /tmp/test/node_modules/joi/lib/string.js ; 

Resolving deps of node_modules/bindings/bindings.js failed.
Improperly-cased require: 'fs' in /tmp/test/node_modules/bindings/bindings.js ; 

Resolving deps of node_modules/glue/node_modules/joi/lib/string.js failed.
Improperly-cased require: 'net' in /tmp/test/node_modules/glue/node_modules/joi/lib/string.js ; 

Resolving deps of node_modules/hapi/node_modules/joi/lib/string.js failed.
Improperly-cased require: 'net' in /tmp/test/node_modules/hapi/node_modules/joi/lib/string.js ; 

Resolving deps of node_modules/hapi/node_modules/subtext/lib/index.js failed.
Improperly-cased require: 'fs' in /tmp/test/node_modules/hapi/node_modules/subtext/lib/index.js 

(I've inserted newlines to aid readability at the expense of length.)

Each hits checkImproperCase with res set to ___shims___ plus the module name, e.g. ___shims___/fs. trueCasePath(res) evaluates to undefined. I'm not yet sure why the shims are there, but adding a check against undefined gets me past the problem.

garthk commented 8 years ago

The next problem might share a root cause:

TypeError: Cannot read property 'split' of undefined
  at path (node_modules/deppack/lib/module-naming.js:21:21)
  at filePath (node_modules/deppack/lib/module-naming.js:31:20)
  at node_modules/deppack/lib/modules.js:55:17
  at Array.reduce (native)
  at usedShims.toArray.reduce (node_modules/deppack/lib/modules.js:54:30)
goshacmd commented 8 years ago

Thanks for the report!

I submitted https://github.com/brunch/deppack/pull/7 to address this.