opencv nodejs _handle error while requiring it in js page - node.js

I have installed the opencv using npm, but when I require it in my js page like this:
var cv = require('opencv');
I get an error
Uncaught TypeError: cannot read property '_handle' of undefined

Related

TypeError: PgMock2 is not a constructor

I am working on mocking pg query, I found a npm package PGMock2 and that suggested importing like
import PgMock2 from 'pgmock2';
const pg = new PgMock2();
By using above, I am getting error TypeError: PgMock2 is not a constructor. Any idea ?
I tried to console PgMock2 and found PgMock2 that I need to do PgMock2.default() and then it worked. Documentation was missing it.

How to use `styled.div` in expo-web?

trying to use styled.div in expo-web
styled-components version is 4.4.1
runtime-error on usage: TypeError: undefined is not a function (near '...styled_components_web__WEBPACK_IMPORTED_MODULE_7__["default"].div...')

Running into error when importing xterm.js in node.js

I am new to node.js, I am trying to run some node.js code from here:
https://xtermjs.org/docs/api/addons/attach/
I got an error:
(node:1576) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
So I renamed the file to .mjs, and I got an error:
import { Terminal } from 'xterm';
^^^^^^^^
SyntaxError: Named export 'Terminal' not found. The requested module 'xterm' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'xterm';
const { Terminal } = pkg;
I followed its suggestion but it just printed a bunch of source code and then error: ReferenceError: self is not defined
What is the right way to do it?

Error with xlsx-style when building angular 6 app

I installed xlsx-style in my angular 6 app via yarn and I get errors when I build my app :
ERROR in ../node_modules/xlsx-style/dist/cpexcel.js
Module not found: Error: Can't resolve './cptable' in 'C:\Users\cabannesj\Documents\Virga3\virga-frontend\node_modules\xlsx-style\dist'
ERROR in ../node_modules/xlsx-style/xlsx.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\cabannesj\Documents\Virga3\virga-frontend\node_modules\xlsx-style'
ERROR in ../node_modules/xlsx-style/ods.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\cabannesj\Documents\Virga3\virga-frontend\node_modules\xlsx-style'
I added 'xlsx.core.min.js' in the script section of my angular.json file.
I don't know what is missing to get xlsx-style work with my app.

Install imdb-api and use it in Angular2 Webpack

I am trying to use the imdb-api repo (https://github.com/worr/node-imdb-api) in my angular2 project, but can't seem to get it working.
I'm working on the newest angular2 webpack (Angular2 Webpack Starter). I usually know how to get libs working, but this one is just not working :(
Have cloned the Angular2 Webpack starter, and made the Npm install and npm start.. everything works great.
Then I have installed version 2.0.0 of imdb-api like this:
npm install --save imdb-api
It installed with no problems.
In a component, (lets say the about component) , I have imported the module like:
import * as imdb from 'imdb-api';
In the constructor, I am trying to console.log(imdb) to see if it's available.
constructor(public route: ActivatedRoute) {
// var imdb = require('imdb-api');
console.log(imdb);
}
As you see, I also tried using the var imdb = require ...
The problem is all this gives me errors I just can't seem to solve. I am getting the following errors:
ERROR in ./~/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\Mikkel\Documents\Programmering\angular2-webpack-starter\node_modules\request\lib'
ERROR in ./~/forever-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\Mikkel\Documents\Programmering\angular2-webpack-starter\node_modules\forever-agent'
ERROR in ./~/forever-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\Mikkel\Documents\Programmering\angular2-webpack-starter\node_modules\forever-agent'
ERROR in ./~/tough-cookie/lib/cookie.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\Mikkel\Documents\Programmering\angular2-webpack-starter\node_modules\tough-cookie\lib'
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\Mikkel\Documents\Programmering\angular2-webpack-starter\node_modules\tunnel-agent'
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\Mikkel\Documents\Programmering\angular2-webpack-starter\node_modules\tunnel-agent'
I have found a post about the request problem. The imdb-api is using the request-promise, thats why I'm getting the error.
The post you find here: https://github.com/request/request/issues/1529
The suggested to add the following:
console: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty'
to the node object in the webpack.config.js file. Have added it to the webpack dev config, but now I don't see any errors at all, but the application wont load.

Resources