Can't run require('opencv4nodejs') - javascript

I'm using macOS Monterey 12.2.1, Apple M1. And in the project directory, I installed opencv-build and opencv4nodejs by this script code:
"scripts": { "postinstall": "npm i opencv-build && npm i opencv4nodejs" }
When I run cv = require('opencv4nodejs'), I got this error message and I can't understand it. How can I run this code correctly?
/usr/local/bin/node /Users/david/Desktop/project2/main.js
/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js:47
throw err
^
Error: Cannot find module '/Users/david/Desktop/project2/node_modules/opencv4nodejs/build/Release/opencv4nodejs'
Require stack:
- /Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js
- /Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/opencv4nodejs.js
- /Users/david/Desktop/project2/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js:40:8)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js',
'/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/opencv4nodejs.js',
'/Users/david/Desktop/project2/main.js'
]
}
Process finished with exit code 1

Use Node 14.18.1, then uninstall opencv4nodejs.
Run export CXXFLAGS="-std=c++14 -Wno-c++11-narrowing"
Run npm install opencv4nodejs

Related

Why npm run dev command is showing error cannot find module '. /dist/rx'

C:\Users\sharm\codeweb\eth-to-do-list>npm run dev
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> eth-to-do-list#1.0.0 dev
> lite-server
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './dist/rx'
Require stack:
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\rx\index.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\browser-sync\dist\file-watcher.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\browser-sync\dist\browser-sync.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\browser-sync\dist\index.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\lite-server\lib\lite-server.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\lite-server\bin\lite-server
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\sharm\codeweb\eth-to-do-list\node_modules\rx\index.js:1:10)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\rx\\index.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\browser-sync\\dist\\file-watcher.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\browser-sync\\dist\\browser-sync.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\browser-sync\\dist\\index.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\lite-server\\lib\\lite-server.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\lite-server\\bin\\lite-server'
]
}

TypeError: Cannot read properties of undefined (reading 'create'). Happens when running npm run build:ssr

Getting an error when running npm run build:ssr to try to deploy my angular application
The error:
firestarter#0.0.0 compile:server
webpack --config webpack.server.config.js --progress --colors
C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:93
throw err;
^
TypeError: Cannot read properties of undefined (reading 'create')
at Object. (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\webpack.server.config.js:5:39)
at Module._compile (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at WEBPACK_OPTIONS (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:114:13)
at requireConfig (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:116:6)
at C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:123:17
at Array.forEach ()
at module.exports (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:121:15)
at C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:71:45
at Object.parse (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\node_modules\yargs\yargs.js:576:18)
at C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:49:8
at Object. (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:366:3)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at runCli (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack\bin\webpack.js:54:2)
at Object. (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack\bin\webpack.js:147:2)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157: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:77:12)
at node:internal/main/run_main_module:17:47
See the code below that the error is pointing to.
I've been trying to figure out why is giving me that error for weeks now.
const webpack = require('webpack');
const WebpackConfigFactory = require('#nestjs/ng-universal')
.WebpackConfigFactory;
module.exports = WebpackConfigFactory.create(webpack, {
// Nest server for SSR
server: './server/main.ts'
});
WebpackConfigFactory no longer exists as Angular is now using CLI Builders to build & serve SSR apps.
Issue reported here

npx react-native init MainApp Giving error (code: 'MODULE_NOT_FOUND',) . What's the isue here

I got this error while running the above command (npx react-native init MainApp)
I have installed the latest version of node and npm. I am not sure why this error is reflected.
Tried clearing the cache changing the node version to 17 but no luck. I am new to this react native.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './error'
Require stack:
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#hapi\hoek\lib\assert.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#hapi\topo\lib\index.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\node_modules\joi\lib\types\keys.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\node_modules\joi\lib\types\function.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\node_modules\joi\lib\index.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\config\schema.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\config\readConfigFromDisk.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\config\index.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\commands\install\install.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\commands\index.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\index.js
- C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\bin.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\priye\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#hapi\hoek\lib\assert.js:3:21)
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 Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#hapi\\hoek\\lib\\assert.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#hapi\\topo\\lib\\index.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\node_modules\\joi\\lib\\types\\keys.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\node_modules\\joi\\lib\\types\\function.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\node_modules\\joi\\lib\\index.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\tools\\config\\schema.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\tools\\config\\readConfigFromDisk.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\tools\\config\\index.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\commands\\install\\install.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\commands\\index.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\index.js',
'C:\\Users\\priye\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\bin.js'
]
}
Hi I myself resolved the issue. I deleted the npm-cache folder from the AppData folder and it worked :). Thanks

Error: Cannot find module '../build/Release/canvas.node' Discord bot Node.JS

The bot worked perfectly until one day (without touching anything) it stopped working and I got this error in the node_modules folder:
internal/modules/cjs/loader.js:834
throw err;
^
Error: Cannot find module '../build/Release/canvas.node'
Require stack:
- /home/container/node_modules/canvas/lib/bindings.js
- /home/container/node_modules/canvas/lib/canvas.js
- /home/container/node_modules/canvas/index.js
- /home/container/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/container/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/container/node_modules/canvas/lib/bindings.js',
'/home/container/node_modules/canvas/lib/canvas.js',
'/home/container/node_modules/canvas/index.js',
'/home/container/index.js'
]
}

SyntaxError: Unexpected identifier with mocha and babel

I have a mocha test file (test/test.js) that starts like this, using ES6 module syntax:
import {promises as fs} from 'fs'
import stepToD3 from '../src/StepToD3'
import assert from "assert"
In addition, I have a babel.config.js file in the root of my project:
module.exports = {
presets: [
"#vue/app",
"#babel/preset-env"
]
}
I then want to test this using Mocha, transpiled through babel. I do so using mocha --require #babel/register test/test.js. However, somewhere during the execution, this fails with the following error:
/home/michael/Programming/cola-step/node_modules/#babel/runtime-corejs2/helpers/esm/asyncToGenerator.js:1
(function (exports, require, module, __filename, __dirname) { import _Promise from "../../core-js/promise";
^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Module._compile (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Object.newLoader [as .js] (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/michael/Programming/cola-step/test/test.js:7:49)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Module._compile (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Object.newLoader [as .js] (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at /usr/lib/node_modules/mocha/lib/mocha.js:231:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/usr/lib/node_modules/mocha/lib/mocha.js:228:14)
at Mocha.run (/usr/lib/node_modules/mocha/lib/mocha.js:536:10)
at Object.<anonymous> (/usr/lib/node_modules/mocha/bin/_mocha:573:18)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
at startExecution (internal/bootstrap/node.js:276:5)
at startup (internal/bootstrap/node.js:227:5)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Why is this failing to understand the ES6 import syntax if I'm using Babel? What is going wrong here?
In this case, I was running my tests with mocha on NodeJS, but my babel.config.js was set up to produce code for the browser. To fix this, I had to create two different babel settings, and then export the right NODE_ENV value before running the appropriate command (e.g. NODE_ENV=test mocha --require #babel/register for tests, and NODE_ENV=production for my webpack production build).
This is my new babel.config.js:
module.exports = {
'env': {
'production': {
'presets': [
[
'#vue/app',
{
// "modules": false,
'targets': ['ie >= 9']
},
'#babel/env'
]
],
'comments': false
},
'test': {
'presets': [
[
'#babel/env',
{'targets': {'node': 'current'}}
]
]
}
}
}

Categories