Cannot find module 'browser-window' with nightmare and nodejs - node.js

I'm having hard time to run nightmare from nodejs. I started with the example provided in the README, tried different version of electron-prebuilt and different tweaks but I'm always getting node that can't find the browser-window module.
Here is my test :
> node --version
v5.3.0
>
> cat .\package.json
{
"name": "webautomation",
"version": "1.0.0",
"private": true,
"description": "testing nightmare.js",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"nightmare": "^2.1.2",
"vo": "^1.0.3"
},
"author": "ECH",
"license": "ISC"
}
>
> npm install
>
> npm ls electron-prebuilt
webautomation#1.0.0 D:\MyEnv\WebAutomation
└─┬ nightmare#2.1.2
└── electron-prebuilt#0.35.4
>
> cat .\main.js
var Nightmare = require('nightmare');
console.log("require done");
dream = Nightmare();
dream.goto('http://yahoo.com');
dream.end();
>
> node main.js
creation done
module.js:338
throw err;
^
Error: Cannot find module 'browser-window'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (D:\MyEnv\WebAutomation\node_modules\nightmare\lib\runner.js:6:21)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
>
Can someone tell me what I'm missing here ?

I got a similar problem with my app and I think its because there was a change in the API or so. Anyway, what I did to fix it was this:
In the main.js file, I replaced the old line
var BrowserWindow = require('browser-window');
with this
var BrowserWindow = require('electron').BrowserWindow;
and then it worked.
You could refer to the thread here: https://github.com/Polymer/polymer-cli/issues/404

Related

AdonisJS Error: class BaseCommand extends ace.Command

I cloned my repo from github and npm install on both folders.
Now, I am trying to run adonis server and I am getting this error.
It works on my other machine at home but when I'm on my laptop it is not working. Is it my fault?
adonis serve --dev
class BaseCommand extends ace.Command {
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (/home/muse/.nvm/versions/node/v16.15.0/lib/node_modules/#adonisjs/cli/src/Commands/Base/index.js:17:31)
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)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/muse/.nvm/versions/node/v16.15.0/lib/node_modules/#adonisjs/cli/src/Commands/New/index.js:13:21)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
NPM audit
>edge.js <5.3.2
Severity: moderate
Cross-site Scripting in edge.js - https://github.com/advisories/GHSA-55r9-7mf8-m382
No fix available
node_modules/edge.js
#adonisjs/framework *
Depends on vulnerable versions of edge.js
node_modules/#adonisjs/framework
>2 moderate severity vulnerabilities
>Some issues need review, and may require choosing
a different dependency.
Package.json
{
"name": "adonis-api-app",
"version": "4.1.0",
"adonis-version": "4.1.0",
"description": "Adonisjs boilerplate for API server with pre-configured JWT",
"main": "index.js",
"scripts": {
"start": "node server.js",
"test": "node ace test"
},
"keywords": [
"adonisjs",
"adonis-app"
],
"author": "",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"#adonisjs/ace": "^11.3.1",
"#adonisjs/auth": "^3.0.7",
"#adonisjs/bodyparser": "~2.0.9",
"#adonisjs/cors": "^1.0.7",
"#adonisjs/fold": "^4.0.9",
"#adonisjs/framework": "^5.0.9",
"#adonisjs/ignitor": "^2.0.8",
"#adonisjs/lucid": "^6.1.3",
"sqlite3": "^5.0.11"
},
"autoload": {
"App": "./app"
}
}

use the Dbus package in an electron app (Build process)

i have this problem when i require DBus from the dbus package
const { app, BrowserWindow } = require("electron");
const DBus = require('dbus');
app.whenReady().then(() => {
var win = new BrowserWindow({ width: 600, height: 500 });
win.loadFile('index.html');
win.webContents.openDevTools();
});
so when i execute this code i get this error :
> electron script.js
App threw an error during load
Error: Module did not self-register: '/home/bislem/projects/test/electron/node_modules/dbus/build/Release/dbus.node'.
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1196:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/bislem/projects/test/electron/node_modules/dbus/lib/dbus.js:3:13)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Module did not self-register: '/home/bislem/projects/test/electron/node_modules/dbus/build/Release/dbus.node'.
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1196:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/bislem/projects/test/electron/node_modules/dbus/lib/dbus.js:3:13)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
I searched for this error and tried some solutions but none of them worked (npm rebuild,npm update,delete the node_modules folder then npm install,use a diffrent version of node using the nvm command), but when runing each package by his own, (run electron using the start script electron ., and run dbus with node script.js) they works correctly.
and there was this when installing the dbus package :
console when installing dbus, console when installing dbus part 2
my package.json file :
{
"name": "electrontest",
"version": "1.0.0",
"description": "",
"main": "script.js",
"scripts": {
"start": "electron script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap": "^4.5.3",
"dbus": "^1.0.7",
"electron": "^10.1.5"
}
}
so my question is what is the correct way to Build/Run such code ? || how to use these two packages side by side ?
You need to run
npm install --save-dev electron-rebuild && npx electron-rebuild
More on using native node modules in electron here

Error: Cannot find module 'selenium-selenium'

Versions are:
nvm --version 0.35.3
npm -v: 6.14.8
node -v: v14.10.0
important package.json parts:
{
"main": "index.js",
"scripts": {
"start": "./node_modules/mocha/bin/mocha index.js",
"install": "bash install.sh",
"clear": "rm -R -f node_modules && rm package-lock.json"
},
"dependencies": {
"chromedriver": "^84.0.1",
"dotenv": "^8.2.0",
"mocha": "^8.1.2",
"selenium-webdriver": "^4.0.0-alpha.7"
}
}
index.js:
require('dotenv').config()
const password = process.env.PASSWORD;
const selenium = require('selenium-selenium');
const chrome = require('selenium-selenium/chrome');
const chromedriver = require('chromedriver');
describe('Init driver and login', () => {
//... Should run through as an empty test but does not
});
and the error I'm getting when I'm running mocha index.js or npm run start:
Error: Cannot find module 'selenium-selenium'
Require stack:
- /home/mts/Desktop/projects/selenium/index.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/mocha.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/one-and-dones.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/options.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/bin/mocha
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:893:15)
at Function.Module._load (internal/modules/cjs/loader.js:743:27)
at Module.require (internal/modules/cjs/loader.js:965:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/home/mts/Desktop/projects/selenium-moco/index.js:11:18)
at Module._compile (internal/modules/cjs/loader.js:1076:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:941:32)
at Function.Module._load (internal/modules/cjs/loader.js:782:14)
at Module.require (internal/modules/cjs/loader.js:965:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.exports.requireOrImport (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js:20:12)
at Object.exports.loadFilesAsync (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js:33:34)
at Mocha.loadFilesAsync (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/mocha.js:427:19)
at singleRun (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run-helpers.js:156:15)
at exports.runMocha (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run-helpers.js:225:10)
at Object.exports.handler (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run.js:366:11)
at /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/node_modules/yargs/lib/command.js:241:49
As simple as possible, but the module is not found - why? Should I try the lowest versions possible? I wanted to avoid the compatibility hell so I used only the newest versions available.
I think you use incorrect package name in your code - selenium-selenium. This package doesn't available on npmjs.org.
Try change this lines in our code:
const selenium = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

react-native command gives syntaxerror

Currently using react-native-cli: 1.0.0 and react-native: 0.26.3
Running react-native command in terminal gives this error.
/Users/appleuser/Desktop/asklegit-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229
throw err;
^
SyntaxError: /Users/appleuser/package.json: Error while parsing JSON - Unexpected end of input
at Object.parse (native)
at OptionManager.addConfig (/Users/appleuser/Desktop/asklegit-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:225:62)
at OptionManager.findConfigs (/Users/appleuser/Desktop/asklegit-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:442:30)
at OptionManager.init (/Users/appleuser/Desktop/asklegit-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:484:12)
at compile (/Users/appleuser/Desktop/asklegit-app/node_modules/babel-register/lib/node.js:112:69)
at loader (/Users/appleuser/Desktop/asklegit-app/node_modules/babel-register/lib/node.js:158:14)
at Object.require.extensions.(anonymous function) [as .js] (/Users/appleuser/Desktop/asklegit-app/node_modules/babel-register/lib/node.js:168:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
Anyone got a clue? Couldn't find anything online :(
This is my package.json
{
"name": "asklegit",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"ios": "react-native run-ios",
"android": "react-native run-android"
},
"dependencies": {
"react": "15.0.2",
"react-native": "0.26.3"
}
}
I don't know under which circumstances but it seems sometimes there is an empty package.json created in the users home directory. A completely empty file is by default not correct syntax so calling applications will produce an error.
Solution is to just delete the empty package.json.

Node/Gulp failing (can't load gulp-sass) outside Visual Studio

We are setting up Gulp with our VS project. When running the tasks from the VS Task Runner, they work flawlessly, but from the command line, it's failing.
Package.json:
{
"name": "OurProject",
"description": "OurProject",
"repository": {
"type": "git",
"url": "https://github.com/something.git"
},
"private": true,
"devDependencies": {
"gulp": "^3.9.0",
"gulp-cached": "^1.1.0",
"gulp-coffee": "^2.3.1",
"gulp-notify": "^2.2.0",
"gulp-sass": "^2.0.4",
"gulp-sourcemaps": "^1.5.2"
}
}
Gulpfile.js (simplified):
var
gulp = require('gulp'),
sass = require('gulp-sass');
gulp.task('scss-compile', function () {
return gulp
.src("./Web/css/**/*.scss")
.pipe(sass())
.pipe(gulp.dest("./Web/css"));
});
Visual Studio claims to be using this command line:
cmd.exe /c gulp -b "C:\AbsoluteProjectPath" --color --gulpfile "C:\AbsoluteProjectPath\Gulpfile.js" scss-compile
Which doesn't work if I try it, because it can't find Gulp. So, I changed the current directory to C:\AbsoluteProjectPath and ran:
cmd.exe /c node_modules\.bin\gulp -b "C:\AbsoluteProjectPath" --color --gulpfile "C:\AbsoluteProjectPath\Gulpfile.js" scss-compile
And I got the following:
C:\AbsoluteProjectPath\node_modules\gulp-sass\node_modules\node-sass\lib\extensions.js:148
throw new Error(['`libsass` bindings not found in ', binaryPath, '. Try re
^
Error: `libsass` bindings not found in C:\AbsoluteProjectPath\node_modules\gulp-sass\node_modules\node-sass\vendor\win32-ia32-14\binding.node. Try reinstalling `node-sass`?
at Object.sass.getBinaryPath (C:\AbsoluteProjectPath\node_modules\gulp-sass\node_modules\node-sass\lib\extensions.js:148:11)
at Object.<anonymous> (C:\AbsoluteProjectPaths\node_modules\gulp-sass\node_modules\node-sass\lib\index.js:16:36)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\AbsoluteProjectPath\node_modules\gulp-sass\index.js:163:21)
at Module._compile (module.js:460:26)
Now, that win32-ia32-14 folder doesn't exist. There is a win32-ia32-11 instead.
What might be happening here?
This turned out to be Visual Studio using a different version of node.js that resolves to a different list of packages.

Resources