What are the steps to implement the `serialport` library in `deno`?

After tinkering with Deno to extract readings from an Arduino, I encountered a roadblock when it came to using the serialport library correctly. Here is what I attempted:


According to a post, packages from pika.dev should work. However, when trying to use pika, I received the following error:

However, no web-optimized "module" entrypoint was found in its package.json manifest.


Using jpsm.org did not resolve the issue either:

import * as SerialPort from "https://dev.jspm.io/serialport";

This resulted in the following error:

error: Uncaught TypeError: exists is not a function

This could be due to the absence of type headers that are typically available with npm via @types/serialport, which are not present on pika.dev or jspm.io.


Even attempting to install serialport and @types/serialport through npm and referencing their local paths like so did not provide a solution:

// @deno-types="./node_modules/@types/serialport/index.d.ts"
import * as SerialPort from "https://dev.jspm.io/serialport";

The resulting error was:

error: relative import path "stream" not prefixed with / or ./ or ../ Imported from "file:///home/user/code/deno-serial-test/node_modules/@types/serialport/index.d.ts"

This indicates an issue with the library dependencies downloaded via npm as they do not have relative paths, implying that all library modules would need to be altered or patched.


The code snippet I'm attempting to execute is:

// import * as SerialPort from "https://dev.jspm.io/npm:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e99a8c9b80888599869b9da9d0c7d9c7d9">[email protected]</a>/lib/index.dew.js";

// @deno-types="./node_modules/@types/serialport/index.d.ts"
import * as SerialPort from "https://dev.jspm.io/serialport";

async function readAvailablePorts() {
    const ports = await SerialPort.list();
    console.log('Available SerialPorts: ', ports);
}

readAvailablePorts();


If anyone has any ideas on how to resolve this issue, your input would be greatly appreciated.

Answer №1

If you're looking to work with the NPM serialport package in Deno, unfortunately it's not feasible due to its heavy reliance on Node.js APIs, particularly stream, which is not supported by the Node Compatibility Library

There have been suggestions that packages from pika.dev can be used instead. However, upon trying them out from Pika, I encountered:

Your best bet would be to opt for packages that are built using plain JavaScript, as opposed to those dependent on Node.js APIs.


For now, your options include either creating your own custom package or patiently waiting for someone to develop one if you wish to interface with Arduino using Deno


If you want further insights into the topic of utilizing NPM modules within Deno, refer to: How to use npm module in DENO?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for combining multiple Vue components into a cohesive npm package?

My project manager at work tasked me with creating a single npm package for all the global components in our Vue project. This package should be easily importable and usable by everyone working on the project, similar to how Vuetify is imported from the no ...

The malfunctioning collapse feature in Bootstrap 4 sidebar within an Angular 6 application

I am trying to find a way to collapse and reopen the sidebar when clicking on a button. I have attempted to create a function to achieve this, but unfortunately it did not work as expected. Important: I need to collapse the sidebar without relying on jque ...

What is the best way to write a function in typescript that verifies whether the argument extends a type argument and then returns the argument?

I need to create a function that checks if the argument's type extends a specific type variable and then returns the argument. Something like this: declare function checkType<T, X extends T>(argument: X): X However, TypeScript gives an error wh ...

Error in NextJS Middleware Server: Invalid attempt to export a nullable value for "TextDecoderStream"

I've recently created a straightforward Next.js application using bun (version 1.0.4, bun create next-app), incorporating app routing with Next.js version 13.5.4 and a designated source directory. My goal was to implement a middleware that restricts a ...

A guide to integrating a component into another component in Angular

Currently, I am encountering an issue with importing a component into another in my Ionic 5.0.0 application. Within my application, I have two separate modules: ChatPageModule and HomePageModule. My objective is to include the Chat template within the Hom ...

Whenever I try to import a function, I encounter the error message "no exported member."

I am facing an issue with my node/typescript application where I am attempting to import a function from another file. In order to export it, I utilized exports.coolFunc = coolFunc, and for importing, I used import {coolFunc} from '../controller/coolS ...

Error: The object 'exports' is not defined in geotiff.js at line 3

Looking to integrate the geotiff library with Angular 6.1.0 and TypeScript 2.9.2. Installed it using npm i geotiff Encountering the following error in the browser console: Uncaught ReferenceError: exports is not defined at geotiff.js:3 After r ...

How can I update a property within an object in a sequential manner, similar to taking turns in a game, using React.js?

I am currently working on a ReactJs project where I am creating a game, but I have encountered an issue. I need to alternate turns between players and generate a random number between 1 and 10 for each player, storing this random number inside their respec ...

Installing ganache-cli globally with npm is unsuccessful due to sudo or permission issues

My npm version is 6.5.0 and node version is v10.10.0. I have never had any issues with npm global installs before. sudo npm install --global ganache-cli npm ERR! code 128 npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master https://github ...

What is the correct way to specify type hints for a Stream of Streams in highlandjs?

I'm currently working with typescript@2 and the highlandjs library. In the typings for highland, there seems to be a missing function called mergeWithLimit(n). This function: Accepts a Stream of Streams, merges their values and errors into a single ...

"Stay away from potential updates that could cause issues with npm-check-updates (ncu)

When using the npm-check-update command, major updates are displayed in red. This feature is visible in the initial image of the documentation. However, is there a method to prevent these disruptive changes from being included in the automatic update pro ...

Embracing Typescript version 2.7 and above allows for utilizing multiple types within a parameter, enabling developers to efficiently handle specific properties

Imagine a scenario where a ChildClass is extending the ParentClass. You can view the code on Stackblitz here. The ChildClass simply adds a public property called "brainPower": class ParentClass{ _me: string; constructor() { this._me = "I'm ...

Tips for effectively managing TypeScript values with various types

I am currently facing an issue with the TS interface shown below: export interface Item { product: string | Product; } When I try to iterate through an array of items, I need to handle the type checking. For example: items = Items[]; items.forEach(ite ...

Tips for sending data returned asynchronously from an Observable in Angular from a Child component to its Parent

I am facing a challenge passing Async data from child to parent component. When I try to access console.log(this.values) within the ngAfterViewInit() method in the parent component's HTML page load, it returns an empty value. However, upon clicking th ...

React App folders are not being properly installed through NPX

Encountering an error message while attempting to use npx create-react-app Husna@LAPTOP-LPCC954R MINGW64 ~/Desktop/React GitHib Project (master) $ npx create-react-app github2020 Creating a new React app in C:\Users\Husna\Desktop\Reac ...

"NODEJS: Exploring the Concept of Key-Value Pairs in Object

I am facing a challenge with accessing nested key/value pairs in an object received through a webhook. The object in req.body looks like this: {"appId":"7HPEPVBTZGDCP","merchants":{"6RDH804A896K1":[{"objectId&qu ...

Is it possible for the Redux inside a React component from npm to clash with the Redux in the container?

I am looking to bundle a React component with npm and incorporate Redux to handle state within the component. If another React project imports my component, will it cause conflicts with the Redux instance of that project? For example: The component code ...

Update the form field with today's date in a JHipster application

In our current project in JHipster, we are facing a challenge with setting the default value of a form field as the current date. JHipster offers a moment format for dates, which is essentially an ngbdatepicker. However, when attempting to change the inpu ...

Error: The property 'send' cannot be read because it is undefined - Node.js

We have integrated a Node.js package called springedge to handle SMS functionality in our project: npm install springedge Below is the code snippet from the file send_messages.js: var springedge = require('springedge'); var params = { &apos ...

Understanding npm dependencies in Visual Studio 2017: tackling the "exclamation - not installed" issue

Scenario: Things I have attempted: 1. "Accessing VS/Solution Explorer and selecting npm/context-right-click-menu/Restore Packages.." 2. Running npm install 3. Trying to install a package called kind-of (which is not currently installed) Unfortunate ...