electron-rebuild doesn't use correct NODE_MODULE_VERSION - node.js

I'm trying to target an electron installation with version 13.4.0 and Node version v14.16.0. However, when I run electron-rebuild on my file it builds for NODE_MODULE_VERSION for 83 (used by Node 14) and not the required 89 (used by electron). Here are some relevant files:
binding.gyp:
{
"targets": [
{
"target_name": "tuxphones",
"sources": ["main.cpp"],
"cflags_cc": [
"-std=c++17"
],
"libraries": [
"-lopus",
"-lpulse"
]
}
]
}
Dockerfile:
FROM node:14-buster-slim
RUN apt-get update
RUN apt-get install -y python3 make libpulse-dev libopus-dev g++
RUN mkdir /build
WORKDIR /build
COPY package.json /build/
RUN npm install
COPY ./native/ /build/
RUN ./node_modules/.bin/electron-rebuild
package.json:
{
"name": "tuxphones",
"version": "1.0.0",
"description": "",
"main": "Tuxphones.plugin.js",
"scripts": {
"rebuild": "electron-rebuild -f",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"electron": "^13.4.0",
"electron-rebuild": "^3.2.5"
},
"author": "ImTheSquid",
"license": "MIT"
}
How should I fix this so that I can build my module correctly against module version 89?

Turns out the #include statement in my C++ file was including the system's Node library over the specific one for Electron.
I changed this:
#include<node/node.h>
To this:
#include<node.h>

Related

node/npm saying "Missing script <scriptname>" even though it exists in current directory

The package.json is:
{
"scripts": {
"test": "find ./js/tests -name '*.test.js' | xargs mocha -R spec",
"start": "node ./scores.js",
"run": "node ./scores.js"
},
"dependencies": {
"aws-sdk": "^2.734.0",
"body-parser": "^1.19.0",
..
"dotenv": "^8.2.0"
},
"name": "scores",
"version": "1.0.0",
"main": "",
"repository": {
"type": "git",
"url": "something"
}
}
npm install has been done and the package-lock.json created. Why are either npm run or npm run-script working?
$npm run-script ./scores.js
npm ERR! missing script: ./scores.js
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/steve/.npm/_logs/2021-03-01T23_01_56_745Z-debug.log
15:01:56/scores $ls -l scores.js
-rw-r--r-- 1 steve staff 21417 Feb 25 06:24 scores.js
I have identically structured package.json and scripts in other sibling directories that do work e.g. the following works via cd ../keys_server; npm run keys_server
$cat ../keys_server/package.json
{
"scripts": {
"test": "find ./js/tests -name '*.test.js' | xargs mocha -R spec",
"keys_server": "node ./keys_server.js",
"start": "node ./keys_server.js"
},
"dependencies": {
"aws-sdk": "^2.734.0",
"body-parser": "^1.19.0",
"express": "^4.17.1",
..
"dotenv": "^8.2.0"
},
"name": "keys_server",
"version": "1.0.0",
"main": "keys_server.js",
"repository": {
"type": "git",
"url": "something"
},
Update #pkumar noticed that the main entry was left empty. I now updated it to :
"main": "scores.js",
and then tried both
npm run-script ./scores.js and npm run scores and npm run scores.js. However none of them work:
$npm run scores
npm ERR! missing script: scores
The 'main' field is empty in package.json. try adding scores.js there and see if it works
The 'main' field is supposed to be the entry point of the server: https://docs.npmjs.com/cli/v7/configuring-npm/package-json
EDIT: The actual reason it's not working is because "scores" had not been defined under the scripts section. After adding that definition it should work
"scripts": {
..
"scores": "node ./scores.js"
}

Unable to copy assets folder to dist in Electron Types, need help on package.json

I am fresher to Electron and TypeScript. I am able to run the simple electron app using Typescript.
Now I wanted to use Splash screen. When I manually copy the image to dist folder, the splash screen comes and all work fine. How can I build the application using yarn build command so that assets folder should be copied to dist folder. My lead said that the copy should work for all platform. I have tried with the following package.json file. It is not an Angular project. It is a simple project.
{
"name": "electron-quick-start-typescript",
"version": "1.0.0",
"description": "A minimal Electron application written with Typescript",
"scripts": {
"copy": "npm run copy:assets",
"copy:assets": "cp -r assets/* dist",
"build1": "tsc -p tsconfig.json && npm run copy",
"build": "tsc -p tsconfig.json",
"build:watch": "tsc -p tsconfig.json --watch",
"copy:assets1": "copy -R /assets dist/assets/",
"copy-files": "xcopy ./assets/*.* ./dist/assets",
"build11": "tsc",
"watch": "tsc -w",
"lint": "tslint -c tslint.json -p tsconfig.json",
"start": "npm run build && electron ./dist/main.js"
},
"repository": "https://github.com/electron/electron-quick-start-typescript",
"build": {
"extraResources": [
{
"from": "./src/assets/",
"to": "dist",
"filter": [
"**/*"
]
}
]
},
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo",
"typescript"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron": "^9.0.4",
"tslint": "^6.1.2",
"typescript": "^3.9.5",
"#trodi/electron-splashscreen": "1.0.0",
"babel-cli": "^6.11.4",
"babel-preset-es2015": "^6.9.0",
"browser-sync": "^2.14.0"
}
}

Unable to run a node.js file with #babel/preset-env

I'm trying to run a simple node.js file which needs the #babel/preset-env preset. The moment I run the js file, I get a message saying
Requires Babel “7.0.0-0” but was loaded with “6.26.3”
To replicate the issue, please try the following in a new folder:
1. Run the following commands
npm init
npm install #babel/register
npm install #babel/core#^7.2.2
npm install #babel/preset-env
Create a .babelrc file with the following
{
"presets": ["#babel/preset-env"],
"plugins": []
}
Create a sample emp.jsx with the following
import React from "react";
class CommentBox extends React.Component {}
Create a parse.js file with the following
require('babel-register')({presets: ['env', 'react']});
let Emp = require('./emp.jsx');
Now run the parse.js file by running
node parse.js
You should see the error mentioned above. I have been trying to fix with for a long time now. Please help.
Many Thanks
followed your instructions and using #babel/register instead with
this package.json run with no issues
tasted on
node : v8.11.2
yarn : 1.12.3
paese.json
require('#babel/register')({});
let Emp = require('./emp.jsx');
console.log(Emp)
packge.json
{
"name": "sof",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.2.2",
"#babel/preset-env": "^7.2.3",
"#babel/register": "^7.0.0"
},
"dependencies": {
"react": "^16.7.0"
}
}
Found the problem. The .babelrc file that contained a reference to #babel/preset-env. Removed it and the js file compiled just fine.

Read package.json version inside package.json

I have a package.json file that looks like this:
{
"name": "myapp",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "webpack-dev-server --port=4200",
"build": "webpack",
"docker-build": "docker build -t myapp .",
"docker-run": "docker run -d --name myapp -p 9090:9090 myapp",
"docker-push": "docker build -t myapp . & docker tag myapp myrepo/myapp:{$VERSION} & docker push myrepo/myapp:{$VERSION}"
},
...
}
Im trying to get the version number when I run npm run docker-push so it will automatically tag the release with the version number of the package.json. How can I achieve this?
You can use the environment variable npm_package_version.
Tip: To see all available environment variables set by npm you can add "printenv | grep npm" as a script:
{
"name": "myapp",
"version": "1.0.0",
"scripts": {
"start": "node app.js",
"version": "echo ${npm_package_version}", // return current version
"vars": "printenv | grep npm" // return all ENV vars with 'npm'
}
// ...
}

How to start my globally installed node application?

I developed small application.
I did this to install developed module globally:
npm install . -g
I got this response:
$ npm install -g .
update-deps-dev#1.0.0 C:\Users\Vladislav.Sharikov\AppData\Roaming\npm\node_modul
es\update-deps-dev
I got my module in place, where other globally installed modules are stored. Also, my module is available by:
npm ls -g --depth=0
Now, I want to start this module from any place on my pc. How should I do this?
I try to run, but getting this:
Vladislav.Sharikov#PC /D/Dev
$ update-deps-dev
sh: update-deps-dev: command not found
I am using Windows 7 x64 + Git Bash.
How should I start my globally installed node application?
My package.json file contents:
{
"name": "update-deps-dev",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"adm-zip": "^0.4.7",
"fs": "0.0.2",
"https": "^1.0.0",
"q": "^1.4.1",
"shelljs": "^0.7.0"
}
}
Not sure about git bash. But in a cross platform way you can simply define a bin field on your package json to tell npm to generate a binary available on your command line later. It really works fine on windows, mac, linux.
Note that it is a per user binary. If you are working on linux it won t install it into /usr/bin, but depending on your system, more probably ~/node_modules/bin.
Suppose your binary is defined into bin.js file, you just need to add a new Object field bin, and foreach bin you want to define a key, the name of the binary, and its value must point to the path of your bin file relative to the package file:
{
"name": "update-deps-dev",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {
"update-deps-dev": "./bin.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"adm-zip": "^0.4.7",
"fs": "0.0.2",
"https": "^1.0.0",
"q": "^1.4.1",
"shelljs": "^0.7.0"
}
}
Read also,
https://docs.npmjs.com/files/package.json#bin
https://docs.npmjs.com/cli/bin

Resources