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

npm faq, npm help broken: TypeError: Cannot read property 'cooked' of undefined #8

Open
deathcap opened this issue Feb 10, 2015 · 2 comments

Comments

@deathcap
Copy link
Owner

npm.commands.faq()
bundle.js:75037 Uncaught TypeError: Cannot read property 'cooked' of undefined
message: "Cannot read property 'cooked' of undefined"
stack: (...)
get stack: function () { [native code] }set stack: function () { [native code] }__proto__: Errorbundle.js:75037 help
bundle.js:77161 Object.keys.concat.forEach.Object.defineProperty.get.commandCache.(anonymous function)
bundle.js:74788 faq
bundle.js:77161 Object.keys.concat.forEach.Object.defineProperty.get.commandCache.(anonymous function)
VM6416:2 (anonymous function)VM5388:777 InjectedScript._evaluateOnVM5388:710 InjectedScript._evaluateAndWrapVM5388:626 InjectedScript.evaluate


npm.commands.help()
bundle.js:75037 Uncaught TypeError: Cannot read property 'cooked' of undefined

something with raw vs cooked terminals? ref GH-6

@deathcap deathcap changed the title npm faq broken, TypeError: Cannot read property 'cooked' of undefined npm faq, npm help broken: TypeError: Cannot read property 'cooked' of undefined Feb 10, 2015
@deathcap
Copy link
Owner Author

This is actually from the missing argument parsing, faq and help do npm.config.get("argv").cooked, which is set in:

./node_modules/nopt/lib/nopt.js:    , cooked = args
./node_modules/nopt/lib/nopt.js:  data.argv = {remain:remain,cooked:cooked,original:original}

and it is an upstream npm bug, not browserify-specific (but admittedly an obscure edge case):

tmp $ node
> var npm = require('npm')
undefined
> npm.load()
undefined
> npm.commands.faq()
TypeError: Cannot read property 'cooked' of undefined
    at EventEmitter.help (/private/tmp/node_modules/npm/lib/help.js:18:36)
    at Object.commandCache.(anonymous function) (/private/tmp/node_modules/npm/lib/npm.js:218:11)
    at EventEmitter.faq (/private/tmp/node_modules/npm/lib/faq.js:8:40)
    at Object.commandCache.(anonymous function) (/private/tmp/node_modules/npm/lib/npm.js:218:11)
    at repl:1:15
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
> npm.commands.help()
TypeError: Cannot read property 'cooked' of undefined
    at EventEmitter.help (/private/tmp/node_modules/npm/lib/help.js:18:36)
    at Object.commandCache.(anonymous function) (/private/tmp/node_modules/npm/lib/npm.js:218:11)
    at repl:1:15
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)

deathcap added a commit that referenced this issue Feb 11, 2015
@deathcap
Copy link
Owner Author

Added a workaround but the real fix is a command-line interface, going through npm's argument parsing cli. require('npm/cli') does this:

npm_cli()
undefined
bundle.js:76 npm command require /node_modules/npm/lib/help.js
bundle.js:75213 
Usage: npm <command>

where <command> is one of:
    access, add-user, adduser, apihelp, author, bin, bugs, c,
    cache, completion, config, ddp, dedupe, deprecate, dist-tag,
    dist-tags, docs, edit, explore, faq, find, find-dupes, get,
    help, help-search, home, i, info, init, install, issues, la,
    link, list, ll, ln, login, ls, outdated, owner, pack,
    prefix, prune, publish, r, rb, rebuild, remove, repo,
    restart, rm, root, run-script, s, se, search, set, show,
    shrinkwrap, star, stars, start, stop, t, tag, test, tst, un,
    uninstall, unlink, unpublish, unstar, up, update, v,
    verison, version, view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    /tmp/npm-undefined/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@undefined /node_modules/npm

but there are a bunch of issues. For one, it only works once because after the require() completes the module is loaded and not reloaded:

http://nodejs.org/api/modules.html#modules_caching

Modules are cached after the first time they are loaded. This means (among other things) that every call to require('foo') will get exactly the same object returned, if it would resolve to the same file.

Multiple calls to require('foo') may not cause the module code to be executed multiple times. This is an important feature. With it, "partially done" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles.

If you want to have a module execute code multiple times, then export a function, and call that function.

but it can be used in webnpm to call the command-line, by setting process.argv beforehand. The zeroth element is "node", first is script name, remaining are the arguments. Added a npm_cli function wrapper for this purpose, example usage:

npm_cli('node', 'npm', 'help', '--long', 'foo')
undefined
bundle.js:76 npm command require /node_modules/npm/lib/help.js
bundle.js:76 npm command require /node_modules/npm/lib/help-search.js
bundle.js:74981 No results for "foo"

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

1 participant