Skip to content

nvim-dap pwa-node adapter leaves ${port} unresolved, causing Node attach failures #1848

Open

Description

@victor-shelepen

I have confirmed that this is a bug related to nvf

  • This is a bug, and not an user error or a support request. I understand that my issue will be closed if it is not a bug in nvf.
  • I have checked the issues tab and confirmed that my issue has not yet been reported. I understand that my issue will be closed if it is a duplicate.

Description

While configuring vim.debugger.nvim-dap.adapters."pwa-node" in nvf, the generated dap adapter keeps port as a literal string "${port}" instead of a concrete runtime value. This leads to failures when trying to attach Node.js debugging with vscode-js-debug.

Relevant config path:

Observed generated Lua adapter snippet:

  • type = "server"
  • host = "127.0.0.1"
  • port = "${port}"
  • executable.command = "/nix/store/...-vscode-js-debug-1.117.0/bin/js-debug"
  • executable.args = { "${port}" }

Using a custom command like DapNodeAttach with request="attach" and target inspector port 9229 still fails due to adapter connectivity behavior around the unresolved placeholder.

Installation Method

Other

Installation Method (Other)

Configured through custom nvf module options for nvim-dap adapter setup.

nvf Version

main

Reproduction steps

  1. Configure nvf nvim-dap adapter for pwa-node using server adapter with dynamic placeholder port.
  2. Set adapter executable to vscode-js-debug and args containing "${port}".
  3. Rebuild/apply configuration and inspect generated dap adapter Lua.
  4. Run attach flow for Node.js (target process started with --inspect=127.0.0.1:9229).
  5. Execute attach command via nvim-dap (e.g., custom DapNodeAttach wrapper).
  6. Observe connection errors.

Expected behavior

The adapter placeholder behavior should resolve to a real runtime port such that js-debug starts correctly as a DAP server and attach succeeds to the Node inspector endpoint.

Actual Behavior

Observed errors include:

  • "DAP Couldn't connect to 127.0.0.1:${port}: ECONNREFUSED"

When trying alternative adapter wiring to connect directly to 9229, attach then fails with:

  • "Content-Length not found in headers: HTTP/1.0 400 Bad Request"
    which indicates the debugger is speaking DAP to a non-DAP endpoint (Node inspector HTTP/WebSocket).

System Information

❯ nix-info --markdown
 - system: `"x86_64-linux"`
 - host os: `Linux 6.18.50, NixOS, 26.05 (Yarara), 26.05.20260911.21a67dc`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.34.8`
 - nixpkgs: `/nix/store/i2wrp0fbhvysy6bcanmwn6smd3jw938f-source`

Relevant log output

Error sample:
DAP Couldn't connect to 127.0.0.1:${port}: ECONNREFUSED

Alternative failure sample:
.../nvim-dap/lua/dap/rpc.lua:30: Content-Length not found in headers: HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8

Configs

{ pkgs, lib, ... }:
{
  programs.nvf = {
    enable = true;

    settings = {
      vim.debugger.nvim-dap = {
        enable = true;
        ui.enable = true;

        # 1. Register the js-debug adapter once
        # adapters.pwa-node = {
        #   type = "server";
        #   host = "127.0.0.1";
        #   port = "\${port}";
        #   executable = {
        #     command = "${pkgs.vscode-js-debug}/bin/js-debug";
        #     args = [ "\${port}" ];
        #   };
        # };

        adapters."pwa-node" = lib.generators.mkLuaInline ''
          function(callback, config)
            callback({
              type = "server",
              host = "127.0.0.1",
              port = "''${port}",
              executable = {
                command = "${pkgs.vscode-js-debug}/bin/js-debug",
                args = { "''${port}" },
              },
            })
          end
        '';

        # # 2. Attach configuration for JS/TS file types
        # configurations = lib.genAttrs [
        #   "javascript"
        #   "typescript"
        #   "javascriptreact"
        #   "typescriptreact"
        # ] (_: nodeConfigurations);
      };

      vim.extraPackages = with pkgs; [
        vscode-js-debug
        nodejs
      ];

      vim.luaConfigRC.dap-attach = ''
        local dap = require("dap")

        vim.api.nvim_create_user_command("DapNodeAttach", function()
          dap.run({
            type = "pwa-node",
            request = "attach",
            name = "Attach to Node.js",
            address = "127.0.0.1",
            port = 9229,
            protocol = "inspector",
            sourceMaps = true,
            cwd = "''${workspaceFolder}",
          })
        end, {})
      '';
    };
  };
}

Activity

  1. added
    bug
    on Oct 20, 2026
  2. horriblename commented on Oct 20, 2026

    @horriblename
    Collaborator

    As a first step, please check :checkhealth dap

    Also let me know if specifying a concrete port number e.g. {port = 9000; executable.args = ["9000"];} works

    Attach your (ideally minimal) config as well

  3. victor-shelepen commented on Oct 20, 2026

    @victor-shelepen
    Author

    I've attached my config to the description.
    I start the application the following way and then I attach to it using the custom function.

    npx tsx --inspect-brk=127.0.0.1:9229 ./src/index.tsx 
    Debugger listening on ws://127.0.0.1:9229/82d7e085-8631-4607-904b-2a628b87e9a0
    For help, see: https://nodejs.org/learn/getting-started/debugging
    { pkgs, lib, ... }:
    {
      programs.nvf = {
        enable = true;
    
        settings = {
          vim.debugger.nvim-dap = {
            enable = true;
            ui.enable = true;
    
            # 1. Register the js-debug adapter once
            # adapters.pwa-node = {
            #   type = "server";
            #   host = "127.0.0.1";
            #   port = "\${port}";
            #   executable = {
            #     command = "${pkgs.vscode-js-debug}/bin/js-debug";
            #     args = [ "\${port}" ];
            #   };
            # };
    
            adapters."pwa-node" = lib.generators.mkLuaInline ''
              function(callback, config)
                callback({
                  type = "server",
                  host = "127.0.0.1",
                  port = "''${port}",
                  executable = {
                    command = "${pkgs.vscode-js-debug}/bin/js-debug",
                    args = { "''${port}" },
                  },
                })
              end
            '';
    
            # # 2. Attach configuration for JS/TS file types
            # configurations = lib.genAttrs [
            #   "javascript"
            #   "typescript"
            #   "javascriptreact"
            #   "typescriptreact"
            # ] (_: nodeConfigurations);
          };
    
          vim.extraPackages = with pkgs; [
            vscode-js-debug
            nodejs
          ];
    
          vim.luaConfigRC.dap-attach = ''
            local dap = require("dap")
    
            vim.api.nvim_create_user_command("DapNodeAttach", function()
              dap.run({
                type = "pwa-node",
                request = "attach",
                name = "Attach to Node.js",
                address = "127.0.0.1",
                port = 9229,
                protocol = "inspector",
                sourceMaps = true,
                cwd = "''${workspaceFolder}",
              })
            end, {})
          '';
        };
      };
    }
  4. victor-shelepen commented on Oct 20, 2026

    @victor-shelepen
    Author

    I also tried a function approach for the latest bindings.

  5. victor-shelepen commented on Oct 20, 2026

    @victor-shelepen
    Author
    :checkhealth dap
    
    ==============================================================================
    dap:                                                                        ✅
    
    dap: Adapters ~
    
    dap.adapter: pwa-node ~
    - ✅ OK is executable: /nix/store/dzfxp1hq6ji43rmarvx3f85hb349l5i7-vscode-js-debug-1.117.0/bin/js-debug
    
    dap: Sessions ~
    - ✅ OK No active sessions
  6. snoweuph commented on Oct 21, 2026

    @snoweuph
    Collaborator
  7. added
    help wanted
    and removed
    bug
    on Oct 21, 2026
  8. horriblename commented on Oct 21, 2026

    @horriblename
    Collaborator

    This worked for me. Note the second arg '127.0.0.1' for the executable. Turns out their default hostname is ::1 so no ipv4. Presumably you can use the ipv6 address instead and drop the second arg

    require'dap'.adapters['pwa-node'] = {
    	executable = {
    		args = { "${port}", "127.0.0.1" },
    		command = "/nix/store/vrjfnmq6c0szn0lbnvzdhynvfnfkjaqb-vscode-js-debug-1.117.0/bin/js-debug",
    	},
    	host = "127.0.0.1",
    	port = "${port}",
    	type = "server"
    }
    
    require'dap'.configurations.javascript = {
    	{
    		cwd = "${workspaceFolder}",
    		name = "Launch file",
    		program = "${file}",
    		request = "launch",
    		stopOnEntry = true,
    		type = "pwa-node"
    	}
    }
    
  9. victor-shelepen commented on Oct 21, 2026

    @victor-shelepen
    Author

    Hello. I've reached some results. But it is not ideal. Here is my current config. Currently, I prefer the attach mode. It uses a callback approach; it uses static variables; it passes an IP address to sure that IPv4 is used. I am new to this topic. I would be pleased to receive some comments to enhance my config.

    { pkgs, lib, ... }:
    {
      programs.nvf = {
        enable = true;
    
        settings = {
          vim.debugger.nvim-dap = {
            enable = true;
            ui.enable = true;
            
            adapters."pwa-node" = lib.generators.mkLuaInline ''
              function(callback, config)
                callback({
                  type = "server",
                  host = "127.0.0.1",
                  port = "4711",
                  executable = {
                    command = "${pkgs.nodejs}/bin/node",
                    args = {
                      "${pkgs.vscode-js-debug}/lib/node_modules/js-debug/dist/src/dapDebugServer.js",
                      "4711",
                      "127.0.0.1"
                    },
                  },
                })
              end
            '';
    
          };
    
          vim.extraPackages = with pkgs; [
            vscode-js-debug
            nodejs
          ];
    
          vim.luaConfigRC.dap-attach = ''
            local dap = require("dap")
    
            vim.api.nvim_create_user_command("DapNodeAttach", function()
              dap.run({
                type = "pwa-node",
                request = "attach",
                name = "Attach to Node.js",
                address = "127.0.0.1",
                port = 9229,
                sourceMaps = true,
                cwd = vim.fn.getcwd(),
              })
            end, {})
          '';
        };
      };
    }
  10. victor-shelepen commented on Oct 21, 2026

    @victor-shelepen
    Author

    My variant does not close the js-debug server, so I can not start again.

    Error: listen EADDRINUSE: address already in use ${port}
        at Server.setupListenHandle [as _listen2] (node:net:2145:21)
        at listenInCluster (node:net:2224:12)
        at Server.listen (node:net:2361:5)
        at CF (/nix/store/dzfxp1hq6ji43rmarvx3f85hb349l5i7-vscode-js-debug-1.117.0/lib/node_modules/js-debug/dist/src/dapDebugServer.js:106:3787)
        at /nix/store/dzfxp1hq6ji43rmarvx3f85hb349l5i7-vscode-js-debug-1.117.0/lib/node_modules/js-debug/dist/src/dapDebugServer.js:106:4090
        at Object.<anonymous> (/nix/store/dzfxp1hq6ji43rmarvx3f85hb349l5i7-vscode-js-debug-1.117.0/lib/node_modules/js-debug/dist/src/dapDebugServer.js:106:4136)
        at Module._compile (node:internal/modules/cjs/loader:1872:14)
        at Object..js (node:internal/modules/cjs/loader:2003:10)
        at Module.load (node:internal/modules/cjs/loader:1594:32)
        at Module._load (node:internal/modules/cjs/loader:1396:12) {
      code: 'EADDRINUSE',
      errno: -98,
      syscall: 'listen',
      address: '${port}',
      port: -1
    }
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

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions