I am just trying to create a basic index like this
currentDB.createIndex({
index: {
fields: ['name']
}
}).then((result) => {
}).catch((error) => {
})
But it just sends me a 500 with an 'unknown_error' error message
I can successfully run all other methods: .getIndexes, .allDocs, .query etc... only this method is failing for some reason.
As mentioned in the documentation:
500 - Internal Server Error
The request was invalid, either because the supplied JSON was invalid,
or invalid information was supplied as part of the request.
You need to provide more details to be able to re-produce your situation.
I tired the createIndex API on NodeJS to see if I run into any issue. I created the following code in a file named server.js:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // Ignore rejection, becasue CouchDB SSL certificate is self-signed
//import PouchDB from 'pouchdb'
const PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-find'))
const db = new PouchDB('https://admin:****#192.168.1.106:6984/reproduce')
db.createIndex({
index: {
fields: ['title']
}
}).then((result) => {
console.log(result)
}).catch((error) => {
console.log(error)
})
When I run the code, the results are fine:
$ node server.js
{ result: 'created',
id: '_design/94407075806d27d94ac764d9aa138a43c015dc1f',
name: '94407075806d27d94ac764d9aa138a43c015dc1f' }
So, at least on NodeJS, there shouldn't be any problem with createIndex. My PouchDB versions are shown below:
{
"name": "reproduce-pouchdb-tls",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"pouchdb": "^6.4.3",
"pouchdb-find": "^6.4.3"
}
}
Related
I use the babel.js node.js API to compile react jsx and js scripts.
I have the following node.js script for example:
// react_transform.js
const fs = require("fs");
code = fs.readFileSync("./samples/sample4.js", 'utf8');
result2 = require("#babel/core").transformSync(code, {
presets: [
"#babel/preset-env",
"#babel/preset-react",
],
plugins: [
"#babel/plugin-transform-runtime",
],
});
fs.writeFileSync(`./out/out4.js`, result2.code);
console.log("y.");
And the input file that has the jsx code is like:
// sample4.js
ReactDOM.render(
<div>
<p>
hoge.
</p>
</div>
,
document.getElementById('root')
);
$(".__upvote").click(async function (e) {
alertify.warning("You need to login.");
});
Without the "#babel/plugin-transform-runtime", line in the node.js script, when I use the script on the browser (where the output code should be located in the production), it causes an error:
VM496:9 Uncaught ReferenceError: regeneratorRuntime is not defined
So, I did research and added the line. But now I started to get a new error:
VM830:5 Uncaught TypeError: _interopRequireDefault is not a function
By the way the output js file is as follows:
// out4.js
"use strict";
var _interopRequireDefault = require("#babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("#babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("#babel/runtime/helpers/asyncToGenerator"));
ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, "hoge.")), document.getElementById('root'));
$(".__upvote").click( /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(e) {
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
alertify.warning("You need to login.");
case 1:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}());
So I again did research about the new error, found an SO post:
reactjs - How to fix TypeError _interopRequireDefault is not a function in Create React App - Stack Overflow
People say:
Add #babel/runtime to the dependency section. That will fix it.
After add "#babel/runtime", I fixed it
So I added that "#babel/runtime" to package.json then npm install-ed. Now the package.json is like (I ommited irrelevant lines):
{
"name": "tmp",
"version": "1.0.0",
"description": "",
"main": "lodash_dev.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"#babel/runtime": "^7.17.8",
},
"devDependencies": {
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#babel/plugin-transform-react-jsx": "^7.17.3",
"#babel/plugin-transform-runtime": "^7.17.0",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
}
}
Then re-run the node.js script, I get the output, I tested it on the page on the browser, however, for some reason the error still persists.
How can I fix this? Thanks.
You're transforming your code with Babel, but you're not running a bundler such as esbuild or webpack.
require() is not a thing in the browser. The bundler's responsibility (among other things) is to take all of those require() calls and resolve them into real modules, and end up with one (or more) .js files that contains all of the require()d code and no require()s.
I get this error: InvalidValueError: The ipfs-repo-migrations package does not have all migration to migrate from version 10 to 11 at verifyAvailableMigrations when I try to spin up ipfs-coord. Please does anyone have an idea on what I should do? Thanks in advance
Here's my code
const IPFS = require('ipfs')
const BCHJS = require('#psf/bch-js')
const IpfsCoord = require('ipfs-coord')
async function start() {
// Create an instance of bch-js and IPFS.
const bchjs = new BCHJS()
const ipfs = await IPFS.create()
// Pass bch-js and IPFS to ipfs-coord when instantiating it.
const ipfsCoord = new IpfsCoord({
ipfs,
bchjs,
type: 'node.js'
})
await ipfsCoord.start()
console.log('IPFS and the coordination library is ready.')
}
start()
Here's my package.json
{
"name": "ipfs-coord-chat-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#psf/bch-js": "^4.20.26",
"ipfs": "^0.55.4",
"ipfs-coord": "^6.7.3",
"nodemon": "^2.0.15"
}
}
I came across this and found deleting the .jsipfs folder in my home directory solved it.
/home/tom/.jsipfs
Be warned though this will remove all previous data that was stored by your node so it would be wise to take a backup or find a way to roll back your dependencies and extract any crucial data.
When I try to execute in console
node compile.js
I get this error.
RangeError: Maximum call stack size exceeded when try Compilation in Solidity
Invox.sol:
pragma solidity ^0.4.25;
contract Invox {
string public message;
function Invox (string initialmessage) public {
message = initialmessage;
}
function setMessage(string _message) public {
message = _message;
}
}
compile.js:
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const invoxPath = path.resolve(__dirname, 'contracts', 'invox.sol');
const source = fs.readFileSync(invoxPath, 'utf8');
//We have replaced the following line, but the issue persists
module.compile = solc.compile(source, 1).contracts[':Invox'];
//console.log(solc.compile(source, 1));
package.json:
{
"name": "invox",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"solc": "^0.4.25"
}
}
npm install --save solc#0.4.17
run the above command and change the solidity version in your invox.sol
pragma solidity ^0.4.25; -> pragma solidity ^0.4.17;
Maybe your nodejs version is too high.
I met this problem when node v12.16.0 is used.
However, when I switched it to v8.5.0, everything works well.
I am working on an electron test application for windows.
The goal is an auto launching application which displays a popup message everytime the windows user logs in.
Scenario:
I'm executing npm start to package my code. (index.js +
package.json)
I execute the generated .exe which will popup my message. (so far so good, right?)
I sign out from windows (CTRL + L ALT + DEL if this is important) and sign in again to test the application.
The popup opens but the default electron welcome page, too.
package.json
{
"name": "test",
"description": "",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"test": "electron .",
"start": "electron-packager . Test --platform=win32 --arch=x64 --overwrite"
},
"author": "",
"license": "MIT",
"build": {
"appId": "com.test.test",
"win": {
"target": "NSIS"
}
},
"dependencies": {
"auto-launch": "^5.0.5"
},
"devDependencies": {
"electron": "latest",
"electron-packager": "^12.1.1"
}
}
index.js
const {app, dialog} = require("electron");
const AutoLaunch = require("auto-launch");
app.on("ready", function(){
dialog.showMessageBox({ message: "We are ready to take off! :-)", buttons: ["OK"] });
let autoLaunch = new AutoLaunch({
name: "test"
// path: app.getPath("exe")
}).isEnabled().then((isEnabled) => {
if (!isEnabled){
autoLaunch.enable();
dialog.showMessageBox({ message: "AutoLaunch enabled.", buttons: ["OK"] });
}
else dialog.showMessageBox({ message: "AutoLaunch already enabled.", buttons: ["OK"] });
});
app.quit();
});
Edit: Found a problem that prevents the package.json being updated. A simple npm info resulted in a completely unexpected output.
Wow, totally forgot about this question.
The solution was following:
Update all dependencies.
Make sure, that the path to the .html / .js file is absolute and correct.
An absolute path start with a /
For example /files/index.html
That's how it works!
I am creating a Visual Studio Code extension and have read that in order to provide a functionality to the StatusBarItem onclick event I need to register a command for the status bar item. How do I do this? When I create a StatusBarItem using window.createStatusBarItem I get an object which doesn't seem to have any string as identifier but the command registering process requires a string as first argument and I am not sure how to associate it with the StatusBarItem.
I have used yeoman to bootstrap a JavaScript extension.
extension.js
const vscode = require('vscode');
const { exec } = require('child_process')
function activate(context) {
console.log('Thanks for installing me! Remember to add a script to run if you want this extension to do anything \
instersting at all :P');
// TODO: make status bar item clickable
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 1000);
function runCommandAndUpdateStatusBarItem () {
// TODO: fetch command from settings
const command = 'git describe --dirty="-$USER"';
exec(`cd ${vscode.workspace.rootPath} && ${command}`, [], (error, stdout, stderr) => {
if (stdout) {
statusBarItem.text = `$(git-commit) ${stdout}`;
statusBarItem.show();
}
else {
vscode.window.showErrorMessage(stderr);
statusBarItem.hide();
}
});
}
statusBarItem.hide();
let disposable = vscode.commands.registerCommand('extension.sayHello', runCommandAndUpdateStatusBarItem);
context.subscriptions.push(statusBarItem);
context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() {
console.log('Oh...so, you hate me? Ok I go away now :(');
}
exports.deactivate = deactivate;
package.json
{
"name": "script-result-info",
"displayName": "Script Result Info",
"description": "Runs a script in shell and puts the result in the statusBar",
"version": "0.0.1",
"publisher": "emilioidk",
"engines": {
"vscode": "^1.23.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:extension.sayHello"
],
"main": "./extension",
"contributes": {
"commands": [
{
"command": "extension.sayHello",
"title": "Hello world"
}
]
},
"scripts": {
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"typescript": "^2.6.1",
"vscode": "^1.1.6",
"eslint": "^4.11.0",
"#types/node": "^7.0.43",
"#types/mocha": "^2.2.42"
}
}
When I create a StatusBarItem using window.createStatusBarItem I get an object which doesn't seem to have any string as identifier
It does not by default since it's optional, yes, but you can set command on it:
statusBarItem.command = 'extension.sayHello';
Check the API docs for StatusBarItem: https://code.visualstudio.com/docs/extensionAPI/vscode-api#StatusBarItem