Node: why does cli option --no-deprecation, --trace-deprecation take no effect in my script

Created on 11 Oct 2017  Â·  4Comments  Â·  Source: nodejs/node

  • Version: v6.11.4
  • Platform: window 64bit
  • Subsystem: cli option

There is my node code below:

var Util = require('util');
Util.print('fdfasd');

And I have excuted it in cli mode with option --no-deprecation or --trace-deprecation, but it takes no effect.

I mean that, if I excute it with --no-deprecation, it would not print any deprecation warning. If I excute it with --trace-deprecation, it would print trace about the usage of Util.print.
I have search with google for half of a day, but no results. Sorry about my poor English.

cli question

Most helpful comment

(I think this is answered.)

All 4 comments

Sorry that I am not following what

I mean that, if I excute it with --no-deprecation, it would not print any deprecation warning. If I excute it with --trace-deprecation, it would print trace about the usage of Util.print.

means. Those seem to be expected behaviors. This is what I got with v6.11.4 on MacOS, are these logs similar to what you are seeing on your machine?

â–¶ node test.js
fdfasd(node:19036) DeprecationWarning: util.print is deprecated. Use console.log instead.

â–¶ node --no-deprecation test.js
fdfasd%

â–¶ node --trace-deprecation test.js
fdfasd(node:19164) DeprecationWarning: util.print is deprecated. Use console.log instead.
    at Object.<anonymous> (/Users/joyee/projects/node-test/16139/test.js:2:6)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:383:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:496:3

I have try again use comman like yours and it success.
I find that the problem roots in the place of --option, when I use the option after script_name ,like node test.js --no-deprecation, it take no effect. When I use the option before script_name ,it works.
Although It works but I can't understand why the location of option metters.
Thanks for your replay.

node test.js --no-deprecation

In this example, --no-deprecation is passed to the test.js script via process.argv rather than being passed to node itself.

You need to pass it before the script file.

(I think this is answered.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeepks1 picture sandeepks1  Â·  3Comments

dfahlander picture dfahlander  Â·  3Comments

filipesilvaa picture filipesilvaa  Â·  3Comments

cong88 picture cong88  Â·  3Comments

akdor1154 picture akdor1154  Â·  3Comments