Compiled against a different Node.js version using NODE_MODULE_VERSION - node.js

Nodejs version: v12.22.11
Electron version: ^11.1.0
RobotJS version: ^0.6.0
The following error message will be prompted when executing the project.
App threw an error during load
Error: The module '\\?\\node_modules\robotjs\build\Release\robotjs.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 85. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1812)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1203:18)
at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1812)
at Module.load (internal/modules/cjs/loader.js:992:32)
at Module._load (internal/modules/cjs/loader.js:885:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
at Module.require (internal/modules/cjs/loader.js:1032:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (\node_modules\robotjs\index.js:1:15)
at Module._compile (internal/modules/cjs/loader.js:1152:30)
I have tried execute npm rebuild and npm install. But this doesn't solve my problem.
20221029-Updated
This is my whole package.json
{
"name": "robotjs-proj",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "electron-builder install-app-deps && node_modules/.bin/electron-rebuild --module-dir .",
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^11.1.0",
"electron-builder": "^23.6.0",
"mathjs": "^8.1.0",
"robotjs": "^0.6.0",
"robotjs-node12": "^0.5.3"
},
"devDependencies": {
"#types/node": "^18.11.7",
"electron-rebuild": "^2.3.4"
}
}

insert postinstall script to your package.json
...
"start": .......,
"preinstall": .....,
"postinstall": "electron-builder install-app-deps && node_modules/.bin/electron-rebuild --module-dir .",
"dist": ....,
...

Related

error: Cannot find module 'postcss' heroku

The website works fine on local, but it fails to deploy on Heroku with a very common error. I am using direct deploy from Github.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'postcss'
Require stack:
- /tmp/build_d7cb8562/node_modules/postcss-cli/index.js
- /tmp/build_d7cb8562/node_modules/postcss-cli/bin/postcss
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/tmp/build_d7cb8562/node_modules/postcss-cli/index.js:14:17)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/tmp/build_d7cb8562/node_modules/postcss-cli/index.js',
'/tmp/build_d7cb8562/node_modules/postcss-cli/bin/postcss'
]
}
ERROR: "prefix:css" exited with 1.
-----> Build failed
This is my package.json file before I tried fixing it by moving devDependencies to dependencies
{
"name": "dopefolio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile:scss": "node-sass sass/main.scss css/style.css -w",
"prefix:css": "postcss --use autoprefixer -b 'last 10 versions' css/style.css -o css/style.css",
"compress:css": "node-sass css/style.css css/style.css --output-style compressed",
"build": "npm-run-all prefix:css compress:css"
},
"author": "",
"license": "GPL-3.0",
"devDependencies": {
"autoprefixer": "^10.3.1",
"node-sass": "^6.0.1",
"npm-run-all": "^4.1.5",
"postcss-cli": "^8.3.1"
}
}
This is my attempted fix:
{
"name": "dopefolio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"autoprefixer": "^10.3.1",
"node-sass": "^6.0.1",
"npm-run-all": "^4.1.5",
"postcss-cli": "^8.3.1"
},
"scripts": {
"compile:scss": "node-sass sass/main.scss css/style.css -w",
"prefix:css": "postcss --use autoprefixer -b 'last 10 versions' css/style.css -o css/style.css",
"compress:css": "node-sass css/style.css css/style.css --output-style compressed",
"build": "npm-run-all prefix:css compress:css"
},
"author": "",
"license": "GPL-3.0",
"devDependencies": {
}
}
It still fails to deploy with the same error. What could be the case?

Problem with deployment on Heroku with 2 package.json files

I'm trying to deploy my app on Heroku, having 2 package.json files.
First is for the frontend:
{
"name": "quiz",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "npm start --prefix server",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"heroku-postbuild": "npm run build --prefix server && ng build --prod"
},
"private": true,
"dependencies": {
"#angular/animations": "~12.0.2",
"#angular/common": "~12.0.2",
"#angular/compiler": "~12.0.2",
"#angular/core": "~12.0.2",
"#angular/forms": "~12.0.2",
"#angular/platform-browser": "~12.0.2",
"#angular/platform-browser-dynamic": "~12.0.2",
"#angular/router": "~12.0.2",
"rxjs": "~6.6.0",
"tslib": "^2.1.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#types/express": "^4.17.13",
"#angular-devkit/build-angular": "~12.0.2",
"#angular/cli": "~12.0.2",
"#angular/compiler-cli": "~12.0.2",
"#types/jasmine": "~3.6.0",
"#types/node": "^12.11.1",
"jasmine-core": "~3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.7.0",
"typescript": "~4.2.3"
},
"engines": {
"node": "16.x",
"npm": "7.x"
}
}
Second is for the backend:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "dist/index",
"scripts": {
"start": "node ./dist/server/index.js",
"dev": "nodemon index.ts",
"build": "tsc -p ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"#types/express": "^4.17.13",
"#types/node": "^16.6.1",
"nodemon": "^2.0.12",
"ts-node": "^10.2.1",
"typescript": "^4.3.5"
},
"dependencies": {
"express": "^4.17.1",
"zone.js": "^0.11.4"
},
"engines": {
"node": "16.x",
"npm": "7.x"
}
}
As my package.json starts first and triggers /server/package.json - first I try to build backend, using "heroku-postbuild" command in main package.json file and after that this command builds Angular app.
But after Heroku runs "start" command it shows such mistake:
Error: Cannot find module 'express'
2021-09-18T17:16:28.140193+00:00 app[web.1]: Require stack:
2021-09-18T17:16:28.140194+00:00 app[web.1]: - /app/server/dist/server/config/express.js
2021-09-18T17:16:28.140194+00:00 app[web.1]: - /app/server/dist/server/index.js
2021-09-18T17:16:28.140199+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2021-09-18T17:16:28.140200+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2021-09-18T17:16:28.140200+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2021-09-18T17:16:28.140200+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:94:18)
2021-09-18T17:16:28.140201+00:00 app[web.1]: at Object.<anonymous> (/app/server/dist/server/config/express.js:6:33)
2021-09-18T17:16:28.140201+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1101:14)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2021-09-18T17:16:28.140203+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-09-18T17:16:28.140204+00:00 app[web.1]: requireStack: [
2021-09-18T17:16:28.140204+00:00 app[web.1]: '/app/server/dist/server/config/express.js',
2021-09-18T17:16:28.140204+00:00 app[web.1]: '/app/server/dist/server/index.js'
2021-09-18T17:16:28.140205+00:00 app[web.1]: ]
2021-09-18T17:16:28.140205+00:00 app[web.1]: }
When I run all those commands locally - it works.
I solved that problem by moving "express" into my main package.json file, but that's not what I'm trying to achieve. I want to have 2 separate json files so I can handle my installed modules for each backend and frontend easily.
What am I doing wrong?
So the problem was actually that I needed to do npm install both in server and frontend folders.
Heroku has a special command 'heroku-prebuild' which helps to prepare every folder to be built.
I created such commands:
"heroku-prebuild": "npm install --prefix server && npm install",
"heroku-postbuild": "npm run build --prefix server && ng build --prod"
Firstly, Heroku runs "heroku-prebuild", which installs all npm modules for both frontend and backend and, after that, it runs "heroku-postbuild", which builds frontend and backend dist folders.
After that it runs "start": "npm start --prefix server" and everything works.

Cannot find module 'babel-node'

I am trying to run some React code on my server-side using node. Following a tutorial, I am trying to add babel to my node server so that JSX gets transpiled to JS.
I added the run scripts to my json.config to use babel-node as below (I use the "watch-server" script for development):
"scripts": {
"start": "start:dev",
"server": "node babel-node ./server/index.js",
"start:dev": "webpack && npm run server",
"start:prod": "webpack && npm run server",
"test": "jest",
"test:debug": "jest --debug",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage --colors",
"watch-server": "nodemon -e js,scss,jsx --ignore '*.bundle*.js' --verbose --exec npm run start:dev"
The issue I get is when I try to run npm run watch-server is an error:
> node babel-node ./server/index.js
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module '/Users/zarnowm/Documents/GitHub/dsr-ux/babel-node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Here is a snippet of my dependencies:
"devDependencies": {
"#babel/core": "^7.4.3",
"#babel/node": "^7.14.9",
"#babel/plugin-proposal-class-properties": "^7.4.0",
"#babel/plugin-proposal-object-rest-spread": "^7.4.3",
"#babel/plugin-transform-runtime": "^7.4.3",
"#babel/preset-env": "^7.4.3",
"#babel/preset-react": "^7.0.0",
"#babel/runtime": "^7.5.0",
And .babelrc:
{
"env": {
"test": {
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"#babel/plugin-proposal-class-properties",
"#babel/plugin-proposal-object-rest-spread",
"#babel/plugin-transform-runtime"
]
}
}
}
Im struggling to figure out the issue...

WARNING: LoopBack connector "mongodb" is not installed

I m following a tutorial to create a react chat application with Loopback3 API but I m getting following Error when i try to run my application server ,I retried to install npm install loopback-connector-mongodb --save but still getting same issue. Do i need to install mongodb again? :-
WARNING: LoopBack connector "mongodb" is not installed as any of the following modules:
./connectors/mongodb
loopback-connector-mongodb
To fix, run:
npm install loopback-connector-mongodb --save
C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\application.js:280
throw err;
^
Error: Cannot create data source "db":
WARNING: LoopBack connector "mongodb" is not installed as any of the following modules:
./connectors/mongodb
loopback-connector-mongodb
To fix, run:
npm install loopback-connector-mongodb --save
at DataSource.setup (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:457:26)
at new DataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:138:8)
at Registry.createDataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\registry.js:364:14)
at dataSourcesFromConfig (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\application.js:570:19)
at Function.app.dataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback\lib\application.js:269:16)
at C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:191:9
at C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:282:5
at Array.forEach (<anonymous>)
at forEachKeyedObject (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:281:20)
at setupDataSources (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:181:3)
at execute (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\lib\executor.js:39:3)
at bootLoopBackApp (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-boot\index.js:154:3)
at Object.<anonymous> (C:\Users\welcome\Desktop\ReactJS\chatServer\server\server.js:28:1)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
Emitted 'error' event on DataSource instance at:
at DataSource.setup (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:457:12)
at new DataSource (C:\Users\welcome\Desktop\ReactJS\chatServer\node_modules\loopback-datasource-juggler\lib\datasource.js:138:8)
[... lines matching original stack trace ...]
at Module.load (internal/modules/cjs/loader.js:950:32)
But Here is my package.json:-
{
"name": "chatServer",
"version": "1.0.0",
"main": "server/server.js",
"engines": {
"node": ">=6"
},
"scripts": {
"lint": "eslint .",
"start": "node .",
"posttest": "npm run lint"
},
"dependencies": {
"compression": "^1.0.3",
"cors": "^2.5.2",
"helmet": "^3.10.0",
"loopback": "^3.22.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^6.2.0",
"loopback-connector-mongodb": "^6.0.1",
"serve-favicon": "^2.0.1",
"strong-error-handler": "^4.0.0",
"ws": "^7.5.3"
},
"devDependencies": {
"eslint": "^3.17.1",
"eslint-config-loopback": "^8.0.0"
},
"repository": {
"type": "",
"url": ""
},
"license": "UNLICENSED",
"description": "chatServer"
}
How do I deal with this?

Tensorflow JS & Electron Forge - Error importing tensorflow js after npm run make

I have built this little app with tensorflow js. I can run it perfectly on Windows 10 using the npm start, however after I successfully run npm run make it becomes impossible to import tensorflow. I get the following error:
Uncaught Error: The specified module could not be found. \\?\C:\Users\teste\AppData\Local\my-app\app-1.0.0\resources\app.asar.unpacked\node_modules\#tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node
at process.func (electron/js2c/asar.js:140)
at process.func [as dlopen] (electron/js2c/asar.js:140)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1016)
at Object.func (electron/js2c/asar.js:140)
at Object.func [as .node] (electron/js2c/asar.js:149)
at Module.load (internal/modules/cjs/loader.js:816)
at Module._load (internal/modules/cjs/loader.js:728)
at Module._load (electron/js2c/asar.js:717)
at Function.Module._load (electron/js2c/asar.js:717)
at Module.require (internal/modules/cjs/loader.js:853)
When I go down to C:\Users\teste\AppData\Local\my-app\app-1.0.0\resources\app.asar.unpacked\node_modules\#tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node the file is there and perfectly accessible
I'm running windows 10, node v12.13.0, electron 8.2.1 with electron forge
My package.json is:
{
"name": "my-app",
"productName": "my-app",
"version": "1.0.0",
"description": "My Electron application description",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\"",
"install": "electron-rebuild --pre-gyp-fix"
},
"keywords": [],
"author": "guzeda",
"license": "MIT",
"config": {
"forge": "./forge.config.js"
},
"dependencies": {
"#electron-forge/plugin-auto-unpack-natives": "^6.0.0-beta.50",
"#tensorflow/tfjs": "^1.5.1",
"#tensorflow/tfjs-node": "^1.5.1",
"electron-reload": "^1.5.0",
"electron-squirrel-startup": "^1.0.0",
"face-api.js": "^0.22.2",
"jquery": "^3.4.1",
"material-design-lite": "^1.3.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.50",
"#electron-forge/maker-deb": "^6.0.0-beta.50",
"#electron-forge/maker-rpm": "^6.0.0-beta.50",
"#electron-forge/maker-squirrel": "^6.0.0-beta.50",
"#electron-forge/maker-zip": "^6.0.0-beta.50",
"electron": "8.2.1",
"electron-rebuild": "^1.10.1"
}
}
My forge.config is:
module.exports = {
makers: [
{
name: '#electron-forge/maker-squirrel',
config: {
name: "my-app"
}
}
],
plugins: [
['#electron-forge/plugin-auto-unpack-natives']
],
packagerConfig:{asar:true}
}
I appreciate any help
I just found out the solution. That happened because the dll needs to be in the same folder as the buddings. The error message was very misleading.
At the end it was necessary to write some post install script to copy the correct dll to the folder and it worked perfectly
Just double checked your code - was to do with your folder structure.
Why are you using tensorflow.js instead of python et al, if i may ask?

Resources