Developing ES6 modules in C++ using Node.js

Here is a previous example showcasing how to create a Node.js addon in C++:
https://nodejs.org/api/addons.html

You can use node-gyp to build it into a common JS module, which works well with the 'require' function. However, when trying to import the compiled module in a .mjs file, it doesn't work.

This command works: node test.js

// test.js
var m = require("./build/Release/addon");
console.log(m.hello());

This command does not work:

node --experimental-modules test.mjs

// test.mjs
import * as m from "./build/Release/addon";
console.log(m.hello());

The error message displayed is:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module

The C++ addon example provided is tailored for the old version of Node.js using common JS. Are there any examples available for creating a C++ addon that can be built into an ES6 module for importing into .mjs files?

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

Can the concept of partial class be used in an AngularJS controller?

Is it possible to organize code into groups using partials in angularjs? The issue is that my controller has become too cluttered with a lot of code for different methods and functionalities, making it difficult to read. I want to maintain the same contro ...

Creating a custom Angular filter that leverages the power of $http - a

I want to make a retrieval request using $http in AngularJS and then display the obtained result on the front-end. To achieve this, I'm using {{ URL-STRING | iframely }}. 'use strict' angular.module( 'iframely', [] ).filter( &ap ...

Issues with Cloud9 Angular and NodeJS connecting to API on a separate port of the same server

I am currently utilizing an AWS Cloud9 IDE for my project. Angular is running on port 8080, while my NodeJS (with Express) server is running on port 8081. In my Node app.js file, I have set up CORS headers as follows: const app = express(); app.use(expre ...

The issue of receiving a "collection is not a function" TypeError often arises when trying to link MongoDB and NodeJS together

I am a newcomer to MongoDB and currently working on establishing a connection between my ExpressJS server and a MongoDB database. Below is the code I have written for this purpose: const PRIMARY_SERVER = "mongodb://localhost:27017/"; const { M ...

The dilemma between installing Electron or installing Electron-Builder: which one

When it comes to installing Electron for an Electron app with React, the method can vary depending on the tutorial. Some tutorials use electron-builder while others do not, but there is little explanation as to why. First: npx create-react-app app cd app ...

What are some creative ways to design the selected tab?

In my Vue parent component, I have multiple child components. There are several elements that toggle between components by updating the current data. The issue is that I am unsure how to indicate which tab is currently active. I've tried various li ...

React Router - Implementing a <Redirect> element rather than a list of child components

Here is the code snippet I am working with: import { Redirect } from 'react-router-dom'; import QPContent from '../QPContent'; class AnswerContainer extends Component { constructor(props) { super(props); this.state = { ...

Is the version number in the package.json file not aligning with what is displayed when checking the version using the npm -

I've noticed that the version of npm in my package.json file is different from the current version. Is there a way to sync them up or is this normal behavior? "dependencies": { "bcryptjs": "^2.4.3", "client" ...

"TypeScript function returning a boolean value upon completion of a resolved promise

When working on a promise that returns a boolean in TypeScript, I encountered an error message that says: A 'get' accessor must return a value. The code snippet causing the issue is as follows: get tokenValid(): boolean { // Check if curre ...

What is preventing me from utilizing react.createContext()?

Hey there, I've been working on integrating the react context api into my project. I followed the steps outlined in this guide: Unfortunately, when I tried to display some of the information, an error occurred. Here is the error message from my cons ...

construct a table utilizing JSON information

If I have data returned from an ajax call that needs to be processed, a table like the following needs to be created: ID NAME Object Type ============================================== 1 SWT-F1-S32-RTR-1 Network Switch 2 ...

npm windows installation proxy problem

When setting up a proxy on Windows 7, I am using the following commands: npm config set proxy http://<username>:<password>@<proxy-server-url>:<port> npm config set https-proxy http://<username>:<password>@<proxy-serv ...

Unable to activate function when closing Vuetify v-alert

Is there a way to trigger a function when the Vuetify v-alert is closed? I have explored the documentation but haven't found any information on this specific functionality. In the codepen example, the dismissible attribute allows for closing the alert ...

I am having an issue with the npm install command. Each time I try running it, I keep receiving an

After posting the output, I find myself unable to comprehend anything. Can someone please guide me on what steps to take next? npm has issued a warning about an old lockfile and advises that supplemental metadata needs to be fetched from the registry due t ...

Manipulate Nested Objects using an Array of Keys

Currently, I am developing a recursive form using React and MUI that is based on a nested object. Throughout this process, it is crucial for me to keep track of the previous keys as I traverse through the recursion. As users interact with the form and mak ...

What is the best way to incorporate conditionals into loops when working with Jade?

I've been working on targeting a specific element within an iteration. each category in categories .menu_category p= category.category_name The code above is in Jade and it's looping through an object called categories. As I' ...

Utilize webpack to import functions from separate files

I am looking to streamline the process of importing and using functions from a different file. Ideally, I would like to simply call these functions by their name without any extra prefixes or naming conventions. However, I am aware that using eval() can po ...

In Redux, it is possible to add characters to an array but for some reason the remove action does not successfully reach the reducer

As a user types or erases characters, I am utilizing redux to update an array of characters. This allows me to set a success flag when the user correctly types the entire phrase. Currently, when typing in characters, the SET_INPUT action in redux fires of ...

Could not connect: AJAX Request denied?

I am currently hosting a Digital Ocean server that runs on a MEN stack composed of MongoDB, Express, and Node. The registration form can be accessed at: When attempting to choose an option from the dropdown menu, I encounter the following error message: G ...

Enhance CKEditor with Linked Select Boxes Plugin

I have ventured into writing a CKEditor Plugin and have grasped the basic concepts. For instance: CKEDITOR.dialog.add( 'addDocumentGroupDialog', function ( editor ) { return { title: 'Link to a document group', min ...