react-native command gives syntaxerror - node.js

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.

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"
}
}

SyntaxError: Unexpected token '||=' on import of pdfjs-dist

Trying to use pdfjs-dist in node js app
Steps:
created new node js app (module) then:-
npm i pdfjs-dist
package.json is:-
"name": "testpdf",
"version": "1.0.0",
"description": "pdf test",
"main": "testpdf.js",
"type": "module",
"scripts": {
"start": "node testpdf.js"
},
"dependencies": {
"pdfjs-dist": "^2.13.216"
}
}
1 line app (testpdf.js) is
import pdfjs from 'pdfjs-dist'
Get this error with the import:
D:\dev\pdf\node_modules\pdfjs-dist\build\pdf.js:1707
return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex);
^^^
SyntaxError: Unexpected token '||='
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at ModuleWrap. (internal/modules/esm/translators.js:199:29)
at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
at async Loader.import (internal/modules/esm/loader.js:166:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5) PS D:\dev\pdf>
If I look at node_modules\pdfjs-dist\build\pdf.js there are multiple instances of use of this operator "||="
I'm no javascript expert but from what I know this is not a valid opertaor and node v14.15.4 doesn't seem to think it is either.
Note this package version (pdfjs-dist 2.13.216) has been available for two months and can't find a similar issue on the net so guessing I am doing something wrong...
Any ideas?
As was on and old version of NodeJS I upgraded to the latest version v18.1.0 and this cleared the issue

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

Cannot find module 'browser-window' with nightmare and nodejs

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

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