Error: Cannot find module 'renderer/utils/localStore' - javascript

I am trying to call userDir function to get userdata folder path in the main/main.ts. I am using the electron-react-boilerplate
const electron = require('electron');
const path = require('path');
const fs = require('fs');
export function userDir() {
return (electron.app || electron.remote.app).getPath('userData');
}
I am caling the userDir function in the main.ts file
import { userDir } from 'renderer/utils/localStore';
userDir()
Error:
Electron encountered an error
Error: Cannot find module 'renderer/utils/localStore'
Require stack:
- /home/prash/Projects/Electron/pomodoro/src/main/main.ts
- /home/prash/Projects/Electron/pomodoro/node_modules/.pnpm/electron#18.3.2/node_modules/electron/dist/resources/default_app.asar/main.js
-
at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
at Function.n._resolveFilename (node:electron/js2c/browser_init:245:1105)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/home/prash/Projects/Electron/pomodoro/node_modules/.pnpm/#cspotcode+source-map-support#0.8.1/node_modules/#cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._load (/home/prash/Projects/Electron/pomodoro/node_modules/.pnpm/runtime-required#1.1.0/node_modules/runtime-required/runtime-required.js:28:44)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/prash/Projects/Electron/pomodoro/src/main/main.ts:15:1)
at Module._compile (node:internal/modules/cjs/loader:1116:14)
at Module.m._compile (/home/prash/Projects/Electron/pomodoro/node_modules/.pnpm/ts-node#10.8.0_wxuian5givsywcqjoc4lpn66fa/node_modules/ts-node/src/index.ts:1597:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1169:10)
```

Related

No such file directory when compile solidity with node fs library

I'm trying to compile solidity using node compile.js. I have attached the code below:
Here is my simple demo structure:
contracts
node_modules
compile.js
Incrementer.sol
package.json
package-lock.json
Here is compile.js
const fs = require('fs');
const solc = require('solc');
const path = require('path');
// Get Path and Load Contract
const inboxPath = path.resolve(__dirname, 'Incrementer.sol');
console.log(inboxPath) // This one provide directory to read (/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
const source = fs.readFileSync(inboxPath, 'utf8'); // still getting stuck on this
// Compile Contract
const input = {
language: 'Solidity',
sources: {
'Incrementer.sol': {
content: source,
},
},
settings: {
outputSelection: {
'*': {
'*': ['*'],
},
},
},
};
const tempFile = JSON.parse(solc.compile(JSON.stringify(input)));
const contractFile = tempFile.contracts['Incrementer.sol']['Incrementer'];
// Export Contract Data
module.exports = contractFile;
Incrementer.sol:
pragma solidity ^0.8.0;
contract Incrementer {
uint256 public number;
constructor(uint256 _initialNumber) {
number = _initialNumber;
}
function increment(uint256 _value) public {
number = number + _value;
}
function reset() public {
number = 0;
}
}
Packages.json
{
"dependencies": {
"solc": "^0.8.0",
"web3": "^1.5.3"
}
}
I have been tried many different approach but still getting errors:
internal/fs/utils.js:314
throw err;
^
Error: ENOENT: no such file or directory, open
'/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
at Object.openSync (fs.js:498:3)
at Object.readFileSync (fs.js:394:35)
at Object.<anonymous> (/Users/amstriker/Desktop/Sdax/OnePlace/contracts/compile.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/steven/Desktop/Sdax/OnePlace/contracts/get.js:2:17)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
}
Any helps would be appreciated!!.
It failed because of space solidity filename( Incrementer.sol). It is working fine after i changed from Incrementer.sol to Incrementer.sol.

It apparently fails to find the module

The code is this and when I try to turn my bot on I get a error that it can't find the file to execute the command.
const fs = require('fs');
module.exports = (client, Discord) =>{
const commandFolders = fs.readdirSync('./commands')
for(const folder [enter image description here][1]of commandFolders){
const command_files = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'))
for(const file of command_files){
const command = require(`./commands/${folder}/${file}`);
if(command.name){
client.commands.set(command.name, command);
}else {
continue
}
}
}
}
This is the error I get when I turn my bot on.
node:internal/modules/cjs/loader:944
throw err;
^
Error: Cannot find module './commands/Fun/8ball.js'
Require stack:
- C:\Users\Desktop\Discordproject\handlers\command_handler.js
- C:\Users\Desktop\Discordproject\index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at Function.Module._load (node:internal/modules/cjs/loader:774:27)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at module.exports (C:\Users\Desktop\Discordproject\handlers\command_handler.js:8:25)
at C:\Users\famil\Desktop\Discordproject\index.js:11:37
at Array.forEach (<anonymous>)
at Object.<anonymous> (C:\Users\Desktop\Discordproject\index.js:10:38)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\Desktop\\Discordproject\\handlers\\command_handler.js',
'C:\\Users\\Desktop\\Discordproject\\index.js'
]
}
Directory Structure:
Your command_handler.js file is inside /handlers/. ./ is used to access the current directory.
Doing ./commands/ doesn't work because the commands folder is not inside of /handlers/
You must first exit the current folder (using ../), then access.
Change all of the './commands' to '../commands'

Unexpected identifier in async awaitCurrentBlock () while running my .js file

I am facing an issue while running my compile.js file using node compile.js .
My code:
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
'nut plug quality level uncle jeans retire guide eagle gossip cluster sudden',
'https://rinkeby.infura.io/v3/37097b2064214600912ad8a746ff433a'
);
const web3 = new Webs(provider);
const deploy = async (() => {
const accounts = await (web3.eth.Accounts());
console.log('Attempting to deploy from account', accounts[0]);
const result = await(new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({gas: '1000000', from: accounts[0]})
);
console.log('contract deployed to', result.options.address);
});
deploy();
After running : node compile.js
Error log:
/home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js:38
async awaitCurrentBlock () {
^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/edureka/sankalp_practice/inbox/node_modules/web3-provider-engine/index.js:4:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
I did my analysis and it seems that "const HDWalletProvider = require('truffle-hdwallet-provider');" is calling for function async awaitCurrentBlock () in /home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js.
So please let me know how to resolve it.
system: Ubuntu
version of node: v6.11.4
version of npm : 5.4.2
your dependency uses "async awaitCurrentBlock" that looks like node 8.* in which case you're simply using too old version of node. You want that dependency, then you have to update, but that will break your code in another way -> you're importing dependencies "async" and "await" which are reserved keywords in Node 8, so you'll have to update your syntax too

Deploying nuxt edge to firebase with function get an error

I try to deploy nuxt project using the latest version of Nuxt which is nuxt-edge to firebase. This is my function code.
const { Nuxt } = require('nuxt-edge')
const express = require('express')
const functions = require('firebase-functions')
const app = express()
const config = {
dev: false,
buildDir: 'nuxt',
build: {
extractCSS: true,
cache: false,
parallel: true,
publicPath: '/assets/'
}
}
const nuxt = new Nuxt(config)
const handleRequest = (req, res) => {
return new Promise((resolve, reject) => {
nuxt.render(req, res, promise => {
promise.then(resolve).catch(reject)
})
})
}
app.use(handleRequest)
exports.jefrydcossr = functions.https.onRequest(app)
It successfully run locally with firebase serve --only hosting,function command. But when I deployed it online and I open the hosting url, I got server error 500.
After I looked at the error log, I got error like this
2018-06-14T12:43:26.094Z D jefrydcossr: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error: only one instance of babel-polyfill is allowed
at Object.<anonymous> (/user_code/node_modules/nuxt-edge/node_modules/babel-polyfill/lib/index.js:10:9)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/node_modules/nuxt-edge/dist/nuxt-legacy.js:50:1)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
2018-06-14T12:43:26.206Z E jefrydcossr: undefined
2018-06-14T12:51:04.440Z N jefrydcossr: undefined
2018-06-14T12:53:28.052Z N jefrydcossr: undefined
The repository of this project here https://github.com/jefrydco/jefrydco-id

Call a helper functions anywhere in the applicaion - Node/Express

I have a controller
import request from 'request-promise'
import env from 'dotenv'
const dotenv = env.config();
/*==================================
= getCPEInfo =
==================================*/
function getCPEInfo(req, res)
{
var $cpeMac = req.body.cpeMac;
return new Promise((resolve, reject) => {
request({ uri: `${process.env.API_HOST}/vse/ext/vcpe/${$cpeMac}` })
.then((cpe) => resolve(JSON.parse(cpe).data))
.catch((error) => reject(error));
});
}
module.exports = {
getCPEInfo
};
I want to call this getCPEInfo() on my other files in my project
I tried import
import generalController from './controllers/general.js'
and call it
generalController.getCPEInfo();
I kept getting
[nodemon] restarting due to changes...
[nodemon] starting `babel-node ./index.js`
/Users/bheng/Desktop/express-app/index.js:72
router.post('/getCPEInfo/:cpeMac', generalController.getCPEInfo);
^
ReferenceError: generalController is not defined
at Object.<anonymous> (/Users/bheng/Desktop/express-app/index.js:37:36)
at Module._compile (module.js:643:30)
at loader (/Users/bheng/Desktop/express-app/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/bheng/Desktop/express-app/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at Object.<anonymous> (/Users/bheng/Desktop/express-app/node_modules/babel-cli/lib/_babel-node.js:154:22)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
[nodemon] app crashed - waiting for file changes before starting...
Can someone please give me a hint ?
import generalController from './controllers/general.js' will refer to the default export from the module, you need to refactor your controller :
import request from 'request-promise'
import env from 'dotenv'
const dotenv = env.config();
/*==================================
= getCPEInfo =
==================================*/
function getCPEInfo(req, res)
{
var $cpeMac = req.body.cpeMac;
return new Promise((resolve, reject) => {
request({ uri: `${process.env.API_HOST}/vse/ext/vcpe/${$cpeMac}` })
.then((cpe) => resolve(JSON.parse(cpe).data))
.catch((error) => reject(error));
});
}
var Mycontroller = {
getCPEInfo
};
export default MyController
Take a look here.

Categories