How to compiler code in solidity version 0.8.17 using npm? - solidity

Trying to compiler code in solidity using npm but getting an error like this
node:assert:400
throw err;
^
AssertionError [ERR_ASSERTION]: Invalid callback object specified.
at runWithCallbacks (D:\BlockChainProjects\inbox\node_modules\solc\wrapper.js:117:34)
at compileStandard (D:\BlockChainProjects\inbox\node_modules\solc\wrapper.js:223:20)
at Object.compileStandardWrapper [as compile] (D:\BlockChainProjects\inbox\node_modules\solc\wrapper.js:229:20)
at Object. (D:\BlockChainProjects\inbox\compiler.js:9:18)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
This was my code that I wrote in compiler.js
const path = require('path')
const fs = require('fs')
//getting solidity compiler
const solc = require('solc')
const inboxPath = path.resolve(__dirname,'contracts','Inbox.sol')
const source = fs.readFileSync(inboxPath,'utf-8')
console.log(solc.compile(source,1));

Related

Why npm can't find module '../../package.json' even if it already exists

The problem: when I start using npm commands I see the same error:
node:internal/modules/cjs/loader:933
const err = new Error(message);
^
Error: Cannot find module '../../package.json'
Require stack:
- C:\Users\Demian\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js
- C:\Users\Demian\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\Demian\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
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> (C:\Users\Demian\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js:2:19)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155: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: [
'C:\\Users\\Demian\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\utils\\unsupported.js',
'C:\\Users\\Demian\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
'C:\\Users\\Demian\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'
]
}
The same problem with npm i, -v, init and etc. The same error is when I start it from C:/user or in a project with package.json where all works before. node works correctly. What should I do?

react native android error after upgrade to 0.67.2 - SyntaxError: Unexpected token =

I have just upgraded from RN 0.63.3 to 0.67.2...and Im now receiving an error when I try to clean project in Android studio
....node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\Server.js:350 processRequest = (req, res, next) => { ^SyntaxError: Unexpected token = at Module._compile (internal/modules/cjs/loader.js:721:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.<anonymous> (....node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\shared\output\bundle.js:12:16) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
If you look at the file path its referring to (node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\Server.js:350)...this is the line of code where its unhappy
processRequest = (req, res, next) => {
this._processRequest(req, res, next).catch(next);
};
Upgrading node to latest version fixed the issue

Invalid shorthand property initializer error connecting to Mongo DB Atlas

I want to connect my project to Mongo DB Atlas. It shows the following error while connecting the Database:
me :~/Desktop/prod$ npm run server
> #0.1.0 server /home/me/Desktop/
> nodemon server.js
[nodemon] 2.0.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions:
js,mjs,json [nodemon] starting `node server.js` Url/keys.js:2
mongoURI = "mongodb+srv://<username>:<password>#cluster0-ttxhq.mongodb.net/test"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/saurabh/Desktop/prod/server.js:10:12)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10) [nodemon] app crashed - waiting for file changes before starting...
My code is :
const express = require("express")
const mongoose = require("mongoose")
const bodyParser = require("body-parser")
const app = express()
app.use(bodyParser.json())
const db = require("./config/keys").mongoURI
mongoose
.connect(db, {
useNewUrlParser: true,
useCreateIndex : true,
useUnifiedTopology : true
})
.then(()=>console.log("Database Connected"))
.catch(err => console.log(err))
const port = process.env.PORT || 5000
app.listen(port, ()=> console.log(`Server Starter on port ${port}`))
keys.js file is:*
modules.exports = {
mongoURI = "MONGODBURI"
}
Try:
modules.exports = {
mongoURI: "MONGODBURI"
}
This is a JSON so we cannot use '=' here.
have you tried IP whitelisting yourAtlas MongoDB cluster?
https://docs.atlas.mongodb.com/security-whitelist/
Medium tutorial

While unit React-native test files with Mocha, it gives error unexpected tocken

In a React-native project, I want to setup unit testing, For this I am using Mocha and Chai. When I run command npm test it executes mocha __tests__/*.js internally. In test file my code is following:
import { expect } from 'chai';
import Adapter from 'enzyme-adapter-react-16';
import { RefundedEmd } from './RefundedEmd';
import React from 'react';
import renderer from 'react-test-renderer';
describe('App', () => {
it('renders correctly', () => {
renderer.create(<App />);
});
});
I get following error in console:
C:\Technical work\Lorex\slf-mobile-impl\__tests__\App-test.js:1
import { expect } from 'chai';
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:311:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:308:14)
at Mocha.run (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:849:10)
at Object.exports.singleRun (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run-helpers.js:108:16)
at exports.runMocha (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run-helpers.js:143:13)
at Object.exports.handler.argv [as handler] (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run.js:305:3)
at Object.runCommand (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\yargs.js:1087:28)
at Object.parse (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\cli.js:68:6)
at Object.<anonymous> (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\bin\mocha:133:29)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! Test failed. See above for more details.

Why am I getting gulp-changed error?

My gulpfile is below -
'use strict';
//dependencies
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var changed = requrie('gulp-changed');
Error after runnning gulp.
Error is for var changed = requrie('gulp-changed'); -
ReferenceError: requrie is not defined
at Object.<anonymous> (/home/lap1/Desktop/ReactJS/react-
test/gulpfile.js:9:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at execute (/usr/lib/node_modules/gulp-
cli/lib/versioned/^3.7.0/index.js:28:18)
at Liftoff.handleArguments (/usr/lib/node_modules/gulp-
cli/index.js:175:63)
Gulp version - 3.9.1
React native version - 2.0.1
I have installed all the dependencies both globally and for the project alone.
there iss a spelling mistake
Replace this
var changed = requrie('gulp-changed');
by
var changed = require('gulp-changed');