-
|
Hello, I'm reporting a bug that makes it impossible to use many standard device types after a fresh installation of @matter/main from npm. While basic components like OnOffLightDevice can be imported and used successfully, other standard components like OnOffPluginUnitDevice, WindowCoveringDevice, and various behaviors (ScenesServer, ModeSelectServer) cannot be imported, resulting in an ERR_MODULE_NOT_FOUND error. The root cause appears to be an incomplete "exports" map in the package.json of the published npm package. The compiled JavaScript files for these devices physically exist in the dist folder, but they don't seem to be exposed through the package's public API. 1. Set up a new Node.js project: 2. Install the latest @matter/main:
3. Create a file test.js to demonstrate the issue: 4. Run the script: node test.js Expected Behavior Actual Behavior Analysis & Additional Context The TypeScript declaration files (.d.ts) also exist, allowing IDEs to provide autocompletion, but the runtime resolution fails. This strongly suggests the issue is not with the library's build process creating the files, but with the package.json "exports" map not being updated to include the paths for these modules. This problem forces users into workarounds (e.g., using multiple OnOffLightDevice endpoints to simulate other devices) instead of using the correct, semantically appropriate device types. Could the maintainers please verify if the "exports" map in the published npm package is complete? Is there another officially supported way these devices should be imported? Thank you for your work on this project. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
|
Thanks for reporting it. Thats indeed a strange thing. and yes the files are there and the exports should also be correct: I also use this way of importing in several projects - but yes all with a typescript build process around it. Can you please try to import the files not dynamically with await but on top of the file - just to see if this makes a difference? @lauckhart any idea? |
Beta Was this translation helpful? Give feedback.
-
|
Hi, thank you for the suggestion. I have updated the test script to use static imports at the top of the file as you requested. Unfortunately, the result is the same. The script still fails with Here is the updated test script: This confirms the issue is not related to the import style. It seems the module is not correctly exposed in the package's "exports" map for a standard Node.js environment. For now, I will have to stick to a workaround using only OnOffLightDevice. Thanks again for your help. |
Beta Was this translation helpful? Give feedback.
-
|
Hm ... according to the file you need to use "on-off-plug-in-unit" because the class is called OnOffPlugInUnitDevice ... Please fix that and you should be fine :-) |
Beta Was this translation helpful? Give feedback.
-
|
Hi, Thank you for the suggestion about the typo in the import path (plug-in vs plugin). You were absolutely right, and correcting it has solved the initial ERR_MODULE_NOT_FOUND error! This is great progress. However, this has uncovered a new, more subtle issue. When we use the correct import path, we now get a different error: To diagnose this, we ran a small inspection script to see what the module actually exports: Inspection Script (test.js): Output:: As the output shows, the module does not export a usable class named OnOffPluginUnitDevice. Instead, it exports a configuration object with that name. This appears to be the root of the SyntaxError. While OnOffLightDevice seems to be exported as a ready-to-use class, OnOffPluginUnitDevice is exported as a definition object, which makes it impossible to import with { OnOffPluginUnitDevice } and use in the Endpoint constructor in the same way. Is there a specific factory function or a different pattern we should use to create a device instance from this definition object? We feel very close to the solution but are missing this final step. Context: To provide more context on what we are trying to achieve, here is a description of the simulated device: The goal is to create a virtual Matter device that acts as a bridge for an MQTT-controlled load controller connected to an oven. The device requires two separate functions, which we would ideally like to expose within a single tile in the SmartThings app: Main Power: A primary On/Off toggle that controls the oven's main power relay. Exclude Mode: A secondary On/Off toggle that controls an "exclude" state. This function is used to temporarily exclude the oven from an automated load management system in the house. Our main challenge has been finding the right Matter Device Type and/or composition of Behaviors in matter.js that can correctly model this and be rendered as a single, multi-function device by a controller like SmartThings. Our attempt to use OnOffPluginUnitDevice as a base, combined with an OnOffServer (for Power) and a ModeSelectServer (for the Exclude mode), seemed like the perfect solution, but as shown above, we are blocked by the module export issue. Given this use case, could you suggest a standard device type or an example that would be the best fit for this kind of "two-function" load controller? We are looking for the most semantically correct and reliable approach. Any example you could point to would be incredibly helpful. Thank you! |
Beta Was this translation helpful? Give feedback.
-
|
Yes and now read my last meassage again please
Notice the captial I in PlugIn ... and thats the whole source. We exactly use the names from the Matter Spec and the devce is called there the same |
Beta Was this translation helpful? Give feedback.
-
|
So in your import the class name AND the import path was both wrong. So you also need to change both |
Beta Was this translation helpful? Give feedback.
-
|
Hi @Apollon77, First, my apologies for the oversight on the typo. After running so many tests, I completely missed the case sensitivity in PlugIn. Thank you for pointing it out – the import now works correctly. My goal is to model a custom load controller for an oven. I need to expose two separate On/Off functions within a single tile in the SmartThings app: Main Power: A primary On/Off switch that controls the oven's main physical power relay. Exclude: A secondary On/Off switch used to inhibit an external overload control system. When "Exclude" is ON, the oven is temporarily removed from the house's automated load management system. To achieve this, I tried creating a "hybrid" device using an Aggregator. My thinking was that the first endpoint (OnOffPlugInUnitDevice) would set the main icon, while the second (OnOffLightDevice) would appear as a secondary control. Here is the code for that attempt: Current Code (oven-hybrid-attempt.js) Unfortunately, this configuration results in two separate tiles on the SmartThings dashboard: one with a socket icon and another with a light bulb icon. It doesn't group them into a single device as hoped. My question is: What is the correct matter.js pattern to create a custom device that is recognized by controllers as a single entity but provides multiple, independent On/Off controls inside it (similar to a power strip)? Should I be using a different root device type, extending a base class, or composing behaviors in a specific way? Any example or guidance would be incredibly helpful. Thanks again for your support. |
Beta Was this translation helpful? Give feedback.
Hm ... according to the file you need to use "on-off-plug-in-unit" because the class is called OnOffPlugInUnitDevice ... Please fix that and you should be fine :-)