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

glob.hasMagic is not a function #637

Closed
ehallander9591 opened this issue Jan 10, 2017 · 10 comments
Closed

glob.hasMagic is not a function #637

ehallander9591 opened this issue Jan 10, 2017 · 10 comments

Comments

@ehallander9591
Copy link

protobuf.js version: <6.4.5>

 [exec] C:\Users\eric_hallander\git\MPXSCore\node_modules\protobufjs\cli\pbts.js:67
 [exec]         if (glob.hasMagic(files[i])) {
 [exec]                  ^
 [exec] TypeError: glob.hasMagic is not a function
 [exec]     at Object.exports.main (C:\Users\eric_hallander\git\MPXSCore\node_modules\protobufjs\cli\pbts.js:67:18)
 [exec]     at Object.<anonymous> (C:\Users\eric_hallander\git\MPXSCore\node_modules\protobufjs\bin\pbts:4:16)
 [exec]     at Module._compile (module.js:570:32)
 [exec]     at Object.Module._extensions..js (module.js:579:10)
 [exec]     at Module.load (module.js:487:32)
 [exec]     at tryModuleLoad (module.js:446:12)
 [exec]     at Function.Module._load (module.js:438:3)
 [exec]     at Module.runMain (module.js:604:10)
 [exec]     at run (bootstrap_node.js:394:7)
 [exec]     at startup (bootstrap_node.js:149:9)

After updating/upgrading to 6.4.5 this issue keeps re-surfacing. I am solving by running npm install from my node_modules/protobufjs directory

Cheers

<please provide a code snippet for reproduction>
<please paste the stack trace of the error if applicable>
@dcodeIO
Copy link
Member

dcodeIO commented Jan 10, 2017

Related: #622

What does the automatic dependency installation look like for you?

@ehallander9591
Copy link
Author

I removed protobufjs and then re-installed

npm remove protobufjs
.
.
.

npm install // letting my package.json do the work

C:\Users\eric_hallander\git\MPXSCore>npm install

MPXSCore@0.0.1 postinstall C:\Users\eric_hallander\git\MPXSCore
tsc

MPXSCore@0.0.1 C:\Users\eric_hallander\git\MPXSCore
-- protobufjs@6.4.5 +-- @protobufjs/codegen@1.0.5 -- @protobufjs/utf8@1.0.7

C:\Users\eric_hallander\git\MPXSCore>node_modules.bin\pbjs
installing CLI dependencies: tmp@0.0.31
protobuf.js v6.4.5 CLI for JavaScript

Consolidates imports and converts between file formats.

-t, --target Specifies the target format. Also accepts a path to require a custom target.
.
.
.
C:\Users\eric_hallander\git\MPXSCore>node_modules.bin\pbts
protobuf.js v6.4.5 CLI for TypeScript

Generates TypeScript definitions from annotated JavaScript files.
.
.
.

C:\Users\eric_hallander\git\MPXSCore>ant
.
.
[exec] Current OS is Windows 7
[exec] Executing 'C:\Users\eric_hallander\git\MPXSCore\node_modules.bin\pbts.cmd' with arguments:
[exec] '--out'
[exec] 'C:\Users\eric_hallander\git\MPXSCore/srcGen/ts/mpxsStaticModule.d.ts'
[exec] 'C:\Users\eric_hallander\git\MPXSCore\srcGen\js\mpxsStaticModule.js'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] C:\Users\eric_hallander\git\MPXSCore\node_modules\protobufjs\cli\pbts.js:67
[exec] if (glob.hasMagic(files[i])) {
[exec] ^
[exec] TypeError: glob.hasMagic is not a function
[exec] at Object.exports.main (C:\Users\eric_hallander\git\MPXSCore\node_modules\protobufjs\cli\pbts.js:67:18)
[exec] at Object. (C:\Users\eric_hallander\git\MPXSCore\node_modules\protobufjs\bin\pbts:4:16)
[exec] at Module._compile (module.js:570:32)
[exec] at Object.Module._extensions..js (module.js:579:10)
[exec] at Module.load (module.js:487:32)
[exec] at tryModuleLoad (module.js:446:12)
[exec] at Function.Module._load (module.js:438:3)
[exec] at Module.runMain (module.js:604:10)
[exec] at run (bootstrap_node.js:394:7)
[exec] at startup (bootstrap_node.js:149:9)
[exec] Result: 1
.
.

@dcodeIO
Copy link
Member

dcodeIO commented Jan 11, 2017

Hmm, it should really install more than just "tmp".

Code locations:
https://github.com/dcodeIO/protobuf.js/blob/master/package.json#L92
https://github.com/dcodeIO/protobuf.js/blob/master/cli/util.js#L74

Any idea?

@ehallander9591
Copy link
Author

Without looking too deep at the code, I wonder if it doesn't load because in some other package I have loaded, glob is loaded, and your check sees that and doesn't load it itself.

For Example, (ignore the glob under protobufjs because this is there because I ran npm install within protobufjs), I have glob at the root node_modules level, but pbjs doesn't see it unless it lies within the protobufjs's node_modules??

$ find node_modules/ -type d -name glob -print
node_modules/@types/glob
node_modules/alsatian/node_modules/glob
node_modules/apidoc-core/node_modules/glob
node_modules/glob
node_modules/protobufjs/node_modules/browserify/test/glob
node_modules/protobufjs/node_modules/file-utils/node_modules/glob
node_modules/protobufjs/node_modules/fileset/node_modules/glob
node_modules/protobufjs/node_modules/glob
node_modules/protobufjs/node_modules/glob-stream/node_modules/glob
node_modules/protobufjs/node_modules/globs-to-files/node_modules/glob
node_modules/protobufjs/node_modules/globule/node_modules/glob
node_modules/protobufjs/node_modules/istanbul-middleware/node_modules/glob
node_modules/protobufjs/node_modules/istanbul-middleware/node_modules/istanbul/node_modules/glob
node_modules/protobufjs/node_modules/vinyl-fs/node_modules/glob
node_modules/protobufjs/node_modules/wd/node_modules/glob
node_modules/protobufjs/node_modules/yamljs/node_modules/glob
node_modules/protobufjs/node_modules/zuul/node_modules/browserify/test/glob
node_modules/protobufjs/node_modules/zuul/node_modules/glob
node_modules/rimraf/node_modules/glob
node_modules/shelljs/node_modules/glob

eric_hallander@EAT-HALLANDER-2 ~/git/MPXSCore
$

@ehallander9591
Copy link
Author

Further evidence for my last statement

$ find node_modules/ -maxdepth 2 -type d ( -name glob -or -name chalk -o -name
uglify-js -o -name jsdoc -o -name minimist -o -name tmp ) -print

node_modules/@types/glob
node_modules/chalk
node_modules/glob
node_modules/jsdoc
node_modules/minimist
node_modules/uglify-js

The only package missing at depth 2 is 'tmp' package.

:) Hope that helps.

@dcodeIO
Copy link
Member

dcodeIO commented Jan 12, 2017

That'd imply that require.resolve sees more than require does. Unexpected. This could be worked around by using require(require.resolve(...)) for these dependencies, maybe.

If this assumption isn't correct, this could be happening because require.resolve is invoked differently:

  • require.resolve("moduleName/package.json") (because not every module has a main file, i.e. jsdoc)
  • require("moduleName")

But that's again a long-shot.

Last but not least require.resolve could be replaced with a custom implementation that explicitly checks for these modules to be present under node_modules/protobufjs.

Need to test.

@dcodeIO
Copy link
Member

dcodeIO commented Jan 12, 2017

Or maybe it's something entirely different: Does the glob module in your root directory export a hasMagic method? Maybe it's just another version that doesn't have it yet.

dcodeIO added a commit that referenced this issue Jan 12, 2017
@ehallander9591
Copy link
Author

It apparently does not :). It appears to be a much older version 3.2.11 where as protobufjs loads 7.1.1

@dcodeIO
Copy link
Member

dcodeIO commented Jan 12, 2017

I now added semver to CLI dependencies. This one is installed without a version check, but everything else is semver-checked now. Give it a shot!

If it now uses an outdated semver that does not support carets (^) or something, it'd still be possible to install semver first if not at least a major version of 5 is present, and then do the rest.

@ehallander9591
Copy link
Author

:)

Bingo!!

Output from pbjs

C:\Users\eric_hallander\git\MPXSCore>node_modules.bin\pbjs
installing glob@^7.1.1 (3.2.11 is outdated)
installing minimist@^1.2.0 (0.0.8 is outdated)
installing tmp@0.0.31 (Cannot find module 'tmp/package.json')
protobuf.js v6.5.0 CLI for JavaScript

and it ran just fine.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants