During fabcar_router coding, the caURL states that url is undefined. There was no problem with npm import.
I couldn't find any problem.
Has anyone experienced a similar error?
Error Message
TypeError: Cannot read property 'url' of undefined
/home/uyh/4jes/MyWeb/routes/fabcar_router.js:14
const caURL = ccp.certificateAuthorities["ca.example.com"].url;
^
TypeError: Cannot read property 'url' of undefined
**at Object.<anonymous> (/home/uyh/4jes/MyWeb/routes/fabcar_router.js:14:60)**
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/uyh/4jes/MyWeb/server.js:10:20)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
[nodemon] app crashed - waiting for file changes before starting...
fabcar_router.js
const caURL = ccp.certificateAuthorities["ca.example.com"].url;
const express = require('express');
const router = express.Router();
const fs = require('fs');
const path = require('path');
const FabricCAServices = require('fabric-ca-client');
const { FileSystemWallet, X509WalletMixin, Gateway } = require('fabric-network');
const ccpPath = path.resolve(__dirname, '..' , 'a', 'connection.json');
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
const ccp = JSON.parse(ccpJSON);
// Create a new CA client for interacting with the CA.
const caURL = ccp.certificateAuthorities["ca.example.com"].url;
const ca = new FabricCAServices(caURL);
// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = new FileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`);
console.log(`Wallet path: ${walletPath}`);
package.json
"dependencies": {
"express": "^4.17.1",
"fabric-ca-client": "^2.2.0",
"fabric-client": "^1.4.17",
"fabric-network": "^2.2.5"
}
Related
I'm looking at this https://book.solmeet.dev/notes/intro-to-anchor written according to the code in the textbook:
TypeError: provider.send is not a function when await provider.send()
import * as anchor from '#project-serum/anchor';
import { Program } from '#project-serum/anchor';
import { AnchorEscrow } from '../target/types/anchor_escrow';
import { PublicKey, SystemProgram, Transaction } from '#solana/web3.js';
import { TOKEN_PROGRAM_ID, Token } from "#solana/spl-token";
import { assert } from "chai";
describe('anchor-escrow', () => {
// Configure the client to use the local cluster.
const provider = new anchor.getProvider();
anchor.setProvider(provider);
const program = anchor.workspace.AnchorEscrow as Program<AnchorEscrow>;
let mintA = null;
let mintB = null;
let initializerTokenAccountA = null;
let initializerTokenAccountB = null;
let takerTokenAccountA = null;
let takerTokenAccountB = null;
let vault_account_pda = null;
let vault_account_bump = null;
let vault_authority_pda = null;
const takerAmount = 1000;
const initializerAmount = 500;
const escrowAccount = anchor.web3.Keypair.generate();
const payer = anchor.web3.Keypair.generate();
const mintAuthority = anchor.web3.Keypair.generate();
const initializerMainAccount = anchor.web3.Keypair.generate();
const takerMainAccount = anchor.web3.Keypair.generate();
it("Initialize program state", async () => {
// Airdropping tokens to a payer.
await provider.connection.confirmTransaction(
await provider.connection.requestAirdrop(payer.publicKey, 10000000000),
"confirmed"
);
// ⚠️ An error has occurred here
await provider.send(
(() => {
const tx = new Transaction();
tx.add(
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: initializerMainAccount.publicKey,
lamports: 100000000,
}),
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: takerMainAccount.publicKey,
lamports: 100000000,
})
);
return tx;
})(),
[payer]
);
});
then run anchor test
Warning: cargo-build-bpf is deprecated. Please, use cargo-build-sbf
cargo-build-bpf child: /Users/yjy/.local/share/solana/install/active_release/bin/cargo-build-sbf --arch bpf
Error: Function _ZN13anchor_escrow9__private8__global8exchange17hb34dfff05db149f5E Stack offset of 4096 exceeded max offset of 4096 by 0 bytes, please minimize large stack variables
Finished release [optimized] target(s) in 0.34s
Found a 'test' script in the Anchor.toml. Running it as a test suite!
Running test suite: "/Users/yjy/Documents/Code/solana/anchor-projects/anchor-escrow/Anchor.toml"
yarn run v1.22.18
warning package.json: No license field
$ /Users/yjy/Documents/Code/solana/anchor-projects/anchor-escrow/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'
anchor-escrow
1) Initialize program state
✔ Initialize escrow
✔ Exchange escrow state
✔ Initialize escrow and cancel escrow
3 passing (598ms)
1 failing
1) anchor-escrow
Initialize program state:
TypeError: provider.send is not a function
at /Users/yjy/Documents/Code/solana/anchor-projects/anchor-escrow/tests/anchor-escrow.ts:45:20
at Generator.next (<anonymous>)
at fulfilled (tests/anchor-escrow.ts:28:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
How can I solve this problem?
It looks like send doesn't exist, but you can use sendAndConfirm if you want to confirm the transction too, or sendAll if you just want to send. That takes an array of Transactions, so you can do:
const tx = new Transaction();
tx.add(
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: initializerMainAccount.publicKey,
lamports: 100000000,
}),
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: takerMainAccount.publicKey,
lamports: 100000000,
})
);
await provider.sendAll([{tx, signers: [payer]}]);
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('#discordjs/rest');
const { Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
gives error after launch:
C:\Users\Flipdanger\Desktop\BOTS\test\deploy-commands.js:14
commands.push(command.data.toJSON());
^
TypeError: Cannot read properties of undefined (reading 'toJSON')
at Object. (C:\Users\Flipdanger\Desktop\BOTS\test\deploy-commands.js:14:29)
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:79:12)
at node:internal/main/run_main_module:17:47
My .sequelize
const path = require('path');
module.exports = {
'config': path.resolve('src', 'config.js'),
'models-path': path.resolve('src', 'models')
};
// config.js
require('dotenv').config({ path: '.env' });
const username = process.env.DATABASE_USERNAME;
const password = process.env.DATABASE_PASSWORD;
const database = process.env.DATABASE_NAME;
const host = process.env.DATABASE_HOST;
const dialect = 'postgres';
module.exports = { username, password, database, host, dialect };
Error on docker:
ERROR: Cannot find "/app/config/config.json". Have you run "sequelize init"?
This does not appear in local. It seems like sequlelize is trying to find the config in the default path rather than the one specified in the .sequelize
Structure:
src
- config.js
.sequelize
The path in .sequelize is relative
I have a problem with Angular 7 SSR server side rendering window and document not found on server site. When run npm run build:ssr && npm run serve:ssr then terminal showing reference error look like ReferenceError: window is not defined
ngOnInit() {
window.scrollTo(0, 0);
}
write in server.ts
/ ssr DOM
const domino = require('domino');
const fs = require('fs');
const path = require('path');
// index from browser build!
const template = fs.readFileSync(path.join(__dirname, '.', 'dist', 'index.html')).toString();
// for mock global window by domino
const win = domino.createWindow(template);
// from server build
const files = fs.readdirSync(`${process.cwd()}/dist-server`);
// mock
global['window'] = win;
more at https://github.com/Angular-RU/angular-universal-starter/blob/master/server.ts
I am trying to resize image in node.js by this program .
https://github.com/LearnBoost/node-canvas/blob/master/examples/resize.js
var Canvas = require('canvas')
, Image = Canvas.Image
, fs = require('fs');
var img = new Image
, start = new Date;
img.src = __dirname + 'flowers.jpg';
console.log('Resized and saved in %dms');
img.onload = function(){
console.log('Resized and saved in buffer');
try{
var width = img.width / 2
, height = img.height / 2
, canvas = new Canvas(width, height)
, ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, width, height);
canvas.toBuffer(function(err, buf){
console.log('Resized and saved in buffer');
fs.writeFile(__dirname + '/resize.jpg', buf, function(){
console.log('Resized and saved in %dms', new Date - start);
});
});
}catch(e){
console.log(sys.inspect(e));
}
};
img.onerror = function(err){
throw err;
};
the program is not going in the onload function why ?
Edit :
give this error while trying img.src after attaching the onload and onerror events?
`Resized and saved in NaNms
/home/reach121/rahul/knox/index.js:33
throw err;
^
Error: error while reading from input stream
at Object.<anonymous> (/home/reach121/rahul/knox/index.js:35:9)
at Module._compile (module.js:404:26)
at Object..js (module.js:410:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)
at Array.0 (module.js:423:10)
at EventEmitter._tickCallback (node.js:170:26)
Using Image Magic giving me this error :
reach121#youngib:~/rahul/knox$ sudo node index.js
node.js:178
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Command failed: execvp(): No such file or directory
at ChildProcess.<anonymous> (/usr/local/lib/node/.npm/imagemagick/0.1.2/package/imagemagick.js:64:15)
at ChildProcess.emit (events.js:67:17)
at Socket.<anonymous> (child_process.js:172:12)
at Socket.emit (events.js:64:17)
at Array.<anonymous> (net.js:826:12)
at EventEmitter._tickCallback (node.js:170:26)
Code :
var im = require('imagemagick');
im.resize({
srcPath: __dirname + '/flowers.jpg',
dstPath: __dirname + '/flowers-small.jpg',
width: '50%'
}, function(err, stdout, stderr){
if (err) throw err
console.log('resized')
});
Have you already tried setting img.src after attaching the onload and onerror events? Just noticed this as a difference between the original example and yours.
Another question: is the onerror event triggered? If so, the thrown exception could be helpful.
Update
If you just want to resize images and don't need to use any canvas-specific operations, simply use ImageMagick and node-imagemagick. I just did a small test and it worked out of the box:
var im = require('imagemagick');
im.resize({
srcPath: __dirname + '/koala.jpg',
dstPath: __dirname + '/koala-small.jpg',
width: '50%'
}, function(err, stdout, stderr){
if (err) throw err
console.log('resized')
});
For the node_imagemagick module to work you need to install the imagemagick CLI interfaces,
On a mac it can be as easy as:
brew install imagemagick
But this really depends on your specific system.
__dirname does not have a trailing slash.
Change it to this:
img.src = __dirname + '/flowers.jpg';
And attach event handlers before setting img.src like #schaermu said.
FYI, your console.log statement uses a %d but there's no variable after the quoted string. (I'm not sure this solves your other errors.)