Tesseract.js spread syntax (ellipsis) error "Unexpected token ..." - javascript

I am trying to use the tesseract.js package in a node app. I am starting with a basic example from the documentation:
Tesseract = require("tesseract.js");
Tesseract.recognize(
'https://tesseract.projectnaptha.com/img/eng_bw.png',
'eng',
{ logger: m => console.log(m) }
).then(({ data: { text } }) => {
console.log(text);
})
However, running this app (in Heroku) yields the following error:
/app/node_modules/tesseract.js/src/index.js:24
...Tesseract,
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
I am trying to resolve this error. There is a "..." in this index.js file in the package code - any ideas why this would be causing a problem? Not sure if I should submit an "issue" about it.

Duh, the problem seems to have been that my Heroku app was using a very outdated version of node, which I found by running
heroku run bash
node -v
I have updated it and everything works fine.

Related

Error: A dynamic link library (DLL) initialization routine failed on electron but it's fine on node js

I'm trying to load a custom module in electron written in D with node_dlang package, which is fine with node, but it fails within electron.
the test with node, that runs just fine, goes like this:
const nativeModule = require('./module.node');
const assert = require('assert');
assert(nativeModule != null);
assert(nativeModule.ultimate() == 42);
But when I went to use it within electron.js, through the preload script, it returns in an error.
the preload script goes like this:
const {
contextBridge,
ipcRenderer
} = require("electron");
const nativeModule = require('./module.node');
const assert = require('assert');
assert(nativeModule.ultimate() == 42);
function pageLoaded()
{
// ...
}
window.addEventListener('DOMContentLoaded', pageLoaded);
the error when I attempt to load the module within electron application is:
A JavaScript error occured in the browser process
--------------------------- Uncaught Exception: Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\001\Desktop\ele\module.node
at process.func [as dlopen] (VM70 asar_bundle.js:5)
at Object.Module._extensions..node (VM43 loader.js:1138)
at Object.func [as .node] (VM70 asar_bundle.js:5)
at Module.load (VM43 loader.js:935)
at Module._load (VM43 loader.js:776)
at Function.f._load (VM70 asar_bundle.js:5)
at Function.o._load (VM75 renderer_init.js:33)
at Module.require (VM43 loader.js:959)
at require (VM50 helpers.js:88)
at Object.<anonymous> (VM88 C:\Users\001\Desktop\ele\preload.js:6)
What's causing this and how do I fix this?
version
node version is: v14.17.0
electron.js: v13.1.1
both are 64-bit.
the module source code goes like this:
import std.stdio : stderr;
import node_dlang;
extern(C):
void atStart(napi_env env)
{
import std.stdio;
writeln ("Hello from D!");
}
int ultimate()
{
return 42;
}
mixin exportToJs! (ultimate, MainFunction!atStart);
it's compiled with dub command line. No arguments.
UPDATE 1 Do I need to rebuild this module? I found this but it didn't work for me either. I installed the electron-rebuild package by npm install --save-dev electron-rebuild and rebuild with .\node_modules\.bin\electron-rebuild.cmd -v 13.1.1 the command ran fine but I still got same error.
UPDATE 2: inside the console, I clicked in the javascript source code file link in the error message (from the exception) it points to this line of code, where there's this comment saying that:
no static exports found
what does that mean? is this related to the methods in D class? they're marked as public... not sure if related
Electron is a Windows-Application and therefore you need to remove output to std. Try to remove
import std.stdio : stderr;
and
import std.stdio;
writeln ("Hello from D!");
and retry import to Electron.
Please refer this (https://stackoverflow.com/a/74280836/9558119) post from me regarding same. Since it is electron build might be missing Visual C++ Build Environment: Visual Studio Build Tools

Editor Framework: Uncaught SyntaxError: Unexpected token )

I download this project:
https://github.com/Tasarinan/editor-framework
I follow all steps:
1) I install Polymer and Electron (and other: phyton, nodejs ecc.)
2) Run all commands:
sh utils/npm.sh install
bower install
gulp update-electron
sh utils/install-builtin.sh
sh demo.sh
The project run fine, but when I open the Grid Panel I have this error:
Uncaught SyntaxError: Unexpected token ) (line 1)
Uncaught SyntaxError: Unexpected token ) (line 28)
ecc.
(() => { // (line 1)
//*************************
Editor.polymerElement({
properties: {
debugInfo: {
type: Object,
value: () => { return { // (Line 28)
xAxisScale: 0,
xMinLevel: 0,
xMaxLevel: 0,
yAxisScale: 0,
yMinLevel: 0,
yMaxLevel: 0,
}; },
},
This is the link of the code:
https://github.com/cocos-creator-packages/ui-grid/blob/master/widget/pixi-grid.js
I don't understand these commands ()=>{} What library I have to add??
Sorry for my bad english and thanks for Help.
Code ()=>{} is from new version of Javascript (ES6) called arrow functions
() => {} == function() {}
Some of the browsers doesn't support new version of javascript and you have to use polyfills. For example if you are using IE you won't be able to see that page.
Polymer has Polymer-cli that has built-in Polymer build command which can transform code into older version of javascript so all browsers can read the code.
Try to open the project in Chrome (fastest browser for such things like HTML imports)

NodeJS, babel build -> regeneratorRuntime is not defined

This morning i got an error with my NodeJS and babel configuration and i have already find the solution but i would like to understand why it happen ?
After building my app with "babel ./src -d ./lib" and then running it with "node lib/index.js" i got this error:
ReferenceError: regeneratorRuntime is not defined
I have found where is the probleme, this is about how i declared a new function:
async function loopIntercom (conversationId, splited) {
// code..
}
After changing the declaration for this new one:
const loopIntercom = async (conversationId, splited) => {
// code..
}
Everything working fine, but why is there a problem with the first method ?

Error with ffi module node.js Uncaught Error: Dynamic Linking Error: Win32 error 193

I want to call a function, which is written in "C" DLL, from node.js JavaScript. I am using "ffi" module in node.js and electron. The function which I want to call is "int FDColor_GetSWVersion(char* softwareVersion)". I am using the below code:
var libm = ffi.Library(__dirname + "\\viewmodels\\FDColor.dll", {
'FDColor_GetSWVersion': [ 'int', ['string' ] ]
});
But I am getting the error:
Uncaught Error: Dynamic Linking Error: Win32 error 193
It looks like that error means you have a 32/64 bit mismatch. You need to build the dll to match the loading process.
I chose the 64-bit DLL and loaded it successfully

Node 6.2/Mocha 2.4.5: syntax errors on string template and default parameters

Running mocha tests in node I'm getting the following syntax errors.
String Template: this one worked on 4.4, but is failing on 6.2.
/home/ubuntu/workspace/lib/admin.js:18
ROOT: `${homeDir}/.config`,
^
SyntaxError: Unexpected token ILLEGAL
full code:
var homeDir = os.homedir(),
configLocations = {
ROOT: `${homeDir}/.config`,
BASE: `${homeDir}/.config/nobjs`,
FILE: `${homeDir}/.config/nobjs/nobjs_config.json`
};
Default Parameter:
/home/ubuntu/workspace/lib/nobutil.js:4
function splitStringToArray(str, seperator = ','){
^
SyntaxError: Unexpected token =
These fail when I try to run mocha tests.
These seem to be supported.
All simple contrived examples seem to be working in the console. Is mocha the problem?
Thanks to #robertklep 's tip, it is a path problem, global mocha running the tests using system installed node on cloud9.
by installing mocha locally and prefixing my path so that mocha is resolved first, mocha calls my default nvm installed node.
export PATH=/home/ubuntu/workspace/node_modules/mocha/bin:$PATH

Categories

Resources