Developing custom node in visual studio code

Hello all
I'd like some assistance with getting an editor set up so that I can use auto-completion etc in visual studio code. I'm using mac OS.

I have my dev folder in home (~/nodeDev/matter).

I've installed the development into the node red via npm install ~/nodeDev/matter (from the .node-red folder).

the development is dependent on @project-chip/matter-node.js and I've installed this with npm install @project-chip/matter-node.js --save

so far so good.

The development is a mix of javascript and typescript. Where I am going wrong is when I try to import classes and variables into code. For example

import { ServerNode } from "@project-chip/matter.js/node";

results in an error "cannot find module '@project-chip/matter.js/node' or its corresponding type declarations."

the folder structure is


โ”œโ”€โ”€ @project-chip
โ”‚   โ”œโ”€โ”€ matter-node.js
โ”‚   โ””โ”€โ”€ matter.js
โ”œโ”€โ”€ node-red-contrib-matter.js -> ../../nodeDev/matter
โ”‚   โ”œโ”€โ”€ lib
โ”‚   โ””โ”€โ”€ src
โ”œโ”€โ”€ signal-exit
โ”‚   โ””โ”€โ”€ dist
โ””โ”€โ”€ write-file-atomic
    โ””โ”€โ”€ lib

the file in development is in ../../nodeDev/matter/src

I suspect that something is awry with the package.json or the tsconfig.json files but must admit to being a newbie on both topics. any help gratefully received.

tsconfig.json

/* Dev configuration */
{
    "compilerOptions": {
        "module": "node16",
        "moduleResolution": "node16",
        "composite": true,
        "forceConsistentCasingInFileNames": true,
        "noImplicitAny": true,
        "noImplicitOverride": true,
        "noUnusedParameters": true,
        "noUnusedLocals": true,
        "strict": true,
        "outDir": "lib"
    },
    "include": [
        "src/*.ts",
        "src/*.js",
        "src/*.mjs",
    ],
    "allowJs": true
}

package.json

{
  "name": "node-red-contrib-matter.js",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "jpadie",
  "license": "ISC",
  "node-red": {
    "nodes": {
      "matter-thermostat-j": "src/thermostat.js",
      "matter-server-j": "src/server.js"
    }
  },
  "dependencies": {
    "@project-chip/matter-node.js": "^0.10.0"
  },
  "devDependencies": {
    "node-red": "^3.0.2"
  },
  "paths": {
    "*": [
      "/Users/jpadie/.node-red/node_modules/*",
      "*"
    ]
  }
}

Hi @jpadie

I don't have any experience with this package - but, just firing up a quick edit, I was able to start the server.

It's @project-chip/matter-node.js not @project-chip/matter.js/node

const {MatterServer} = require("@project-chip/matter-node.js")

Screenshot 2024-08-17 at 12.33.26

thanks - I don't have an issue with the project-chip package, nor starting the server. I've done lots of development in that (and ServerNode is accessed via @project-chip/matter.js/node by the by, there are overlapping exports).

the challenge I am getting is the incorrect path resolution and associated lack of auto-completion.

Right, sorry - I probably don't know enough about the schematics of this matter project.
I think there is a node that uses it however - by our very own @sammachin

Might be a good resource?

yup - there are a few projects using it, and I'm building another after fezvrasta has stopped maintaining his project.

I'm new to developing in these interpreted / semi-compiled languages though (although very experienced in php) and so am struggling with how to set up the package.json and tsconfig.json to make autocomplete and other extensions work in visual studio code.

When just developing within the project-chip ecosystem it works wonderfully. the challenge (for me) seems to be getting the IDE to work when there are multiple packages.

thanks for your help. I have now resolved this by opening the developer environment at the .node-red folder rather than the development folder level. Perhaps obvious to those who are familiar!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.