Skip to content

node.config.json doesn't respect optionally-valued or aliased options #57960

Description

@avivkeller

Version

v23.11.0

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

No response

What steps will reproduce the bug?

Create a node.config.json with the following content:

{
  "nodeOptions": {
    "inspect": true
  }
}

Run:

> node --experimental-default-config-file
Unable to resolve "true": unknown node or service

How often does it reproduce? Is there a required condition?

N/A

What is the expected behavior? Why is that the expected behavior?

The expected behavior would be that the configuration file understands that setting a flag to true is the equal to applying node --flag, whereas setting a flag to an alternative value is the equal of applying node --flag=value, even for aliased options.

What do you see instead?

When supplying true,

Unable to resolve "true": unknown node or service

When supplying a string value, like 127.0.0.1:

Invalid value for --inspect
node.config.json: invalid content

Additional information

No response

Activity

  1. geeksilva97 commented on Apr 21, 2025

    @geeksilva97
    Contributor

    Inspect option is reaching the boolean case:

    case options_parser::OptionType::kBoolean: {

    When a non-boolean is provided, it displays the error Invalid value for --inspect. When providing a boolean, it does this --inspect=true which cannot be interpreted by

    fprintf(out_, "Unable to resolve \"%s\": %s\n", host_.c_str(),
    , since whan a value is provided it expects a host:port (https://nodejs.org/api/cli.html#--inspecthostport)

  2. marco-ippolito commented on Apr 21, 2025

    @marco-ippolito
    Member

    It expects an hostport value, if you pass any other value it will throw an error

  3. avivkeller commented on Apr 21, 2025

    @avivkeller
    MemberAuthor

    It expects an hostport value, if you pass any other value it will throw an error

    It should also accept true, to enable inspection on the default port. Regardless, if any non-boolean value is passed, it'll fail validation with node.config.json: invalid content.

    Even in the schema it expects a boolean:

    "inspect": {
      "type": "boolean"
    },
  4. marco-ippolito commented on Apr 21, 2025

    @marco-ippolito
    Member

    Probably env_options_map contains the same value twice with different accepted types. This behavior is currently not supported. PR welcome

  5. geeksilva97 commented on Apr 21, 2025

    @geeksilva97
    Contributor

    Will give it a try, folks

  6. added
    configIssues and PRs related to Node.js configuration and feature settings.
    on Apr 24, 2025
  7. marco-ippolito commented on Apr 24, 2025

    @marco-ippolito
    Member

    So I don't think this is a config bug.
    For example:

    marcoippolito@marcos-MacBook-Pro-2 node % NODE_OPTIONS=--inspect=true node -p '1'          
    Unable to resolve "true": unknown node or service
    1
    

    The error is thrown by the --inspect flag not by the config parser.
    If you want to it to support a boolean value the --inspect implementation needs to be changed.
    In the config since its a json you cannot leave the value empty.
    Using null could be interepreted as a value so 🤷🏼
    The weird part is that inspect expects a boolean value but it cannot parse it 😆

  8. geeksilva97 commented on Apr 24, 2025

    @geeksilva97
    Contributor

    you are correct, it's on inspect side

    #57960 (comment)

  9. geeksilva97 commented on Apr 24, 2025

    @geeksilva97
    Contributor

    At first, I wanted to turn --inspect=true into --inspect in the config implementation. But maybe going directly in the inspector is a more reasonable approach.

  10. thisloke commented on Jun 6, 2025

    @thisloke

    I was dealing with this problem just today and i cannot figure out why until i found this open issue :D

    Anyway, i had same problem but using --inspect-wait flag, so i go through the code and i found that the problem afflicts all inspector options:

    • --inspect=
    • --inspect-wait=
    • --inspect-brk=
    • --inspect-brk-node= // Defined but not callable from cli, so not an issue (for now)

    But NOT --inspect-port= itself (which expects a string value).

    Here some runs:

    $ node -v
    v23.11.0
    
    # The problematic case - inspect flags with boolean values
    $ NODE_OPTIONS=--inspect=true node -p '1'
    Unable to resolve "true": unknown node or service
    1
    
    $ NODE_OPTIONS=--inspect-wait=true node -p '1'
    Unable to resolve "true": unknown node or service
    1
    
    $ NODE_OPTIONS=--inspect-brk=true node -p '1' 
    Unable to resolve "true": unknown node or service
    1
    
    # But this works fine
    $ NODE_OPTIONS=--inspect-port=true node -p '1'
    1

    @geeksilva97 there's something in the code that look me a little bit strange and i was not able to debug it effectively (due my lack of c++ knowledge):

    File: node_options.cc
    Method: DebugOptionsParser::DebugOptionsParser())

    AddAlias("--inspect=", { "--inspect-port", "--inspect" });
    ...
    AddAlias("--inspect-wait=", {"--inspect-port", "--inspect-wait"});
    ...
    AddAlias("--inspect-brk=", { "--inspect-port", "--inspect-brk" });

    that invoke this AddAlias method that seems doing 2 things:

    1. Set --inspect-port to "true"
    2. Enable `--inspect
      😕

    And, another bigger problem that i see is the misconception of how we always used --inspect option, it seems that it was originally though to get just a boolean as input, but we always used passing host:port.
    As you can see:

    • --inspect is defined as a boolean option (&DebugOptions::inspector_enabled)
    • But --inspect=true doesn't work because the alias tries to parse "true" as a host:port
    • In JSON config files, you can't leave boolean values empty, so "inspect": true is the logical way to specify it, but it's not what cpp expected.

    So, who's wrong? the cpp implementation of inspect, the parser or the documentation?

    Hope this research it will help to fix the issue.

  11. geeksilva97 commented on Jun 7, 2025

    @geeksilva97
    Contributor

    that invoke this AddAlias method that seems doing 2 things:

    Set --inspect-port to "true"
    Enable `--inspect

    Hi @thisloke . You are correct on this

    When you execute node --inspect=true is expands to node --inspect-port=true --inspect that's why it gives that error.


    i see is the misconception of how we always used --inspect option, it seems that it was originally though to get just a boolean as input

    In Node, boolean options don't need an input. The way to enable disable an options is with the --no prefix. You can see more details about it in this comment. So, --inspect is indeed a boolean. It doesn't need an input.

    In JSON config files, you can't leave boolean values empty, so "inspect": true is the logical way to specify it, but it's not what cpp expected.

    That's what my PR addressed. You should be able to have "inspect": true" in your config file since version 24.0.0

  12. thisloke commented on Jun 9, 2025

    @thisloke

    @geeksilva97 amazing, so i think it will also solve the problem with --inspect-wait=true and --inspect-brk=true because the issues was how --inspect-port=true was expanded and both (-wait, -brk) expanded also --inspect-port=true and now they will just expand --inspect-port instead.

  13. geeksilva97 commented on Jun 18, 2025

    @geeksilva97
    Contributor

    @geeksilva97 amazing, so i think it will also solve the problem with --inspect-wait=true and --inspect-brk=true because the issues was how --inspect-port=true was expanded and both (-wait, -brk) expanded also --inspect-port=true and now they will just expand --inspect-port instead.

    Yeah, most likely. You can let me know about any issues

  14. geeksilva97 commented on Jul 20, 2025

    @geeksilva97
    Contributor

    Closing again since I accidentally reopened it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    configIssues and PRs related to Node.js configuration and feature settings.confirmed-bugIssues and PRs for confirmed bugs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions