Cannot require nodejs files in electron worker process - javascript

I am running a worker on a page of electron after a button click which runs the beginning part of the file just fine. But it gives me the error:
node:internal/modules/cjs/loader:940 Uncaught Error: Cannot find module './bar'
Require stack:
- electron/js2c/worker_init
at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
at o._resolveFilename (node:electron/js2c/worker_init:33:1095)
at Module._load (node:internal/modules/cjs/loader:785:27)
at c._load (node:electron/js2c/asar_bundle:5:13343)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at 3a43803….js:21:5
foo.js is in the same directory as bar.js which is being run as a worker.
I checked the location of the directory and it shows:
C:\Users\programmer\project\node_modules\electron\dist\resources\electron.asar\worker
I expect the locaction to be:
C:\Users\programmer\project\dist\src
P.S. I researched further and found this but the solution for it did not work for me despite being my exact problem.

Related

Error while running an exe compiled with PKG

im compiling a file with PKG. But whenever I try to run the file it gives this error.
Error
All versions are up to date.
I'm trying to run my simple javascript code on another computer and this error pops up.
Error: Cannot find module 'C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-x64\node_sqlite3.node'
Require stack:
- C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\sqlite3-binding.js
- C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\sqlite3.js
- C:\snapshot\highu\OneDrive\Masaüstü\XXX\.\.\.\.\.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Module._load (node:internal/modules/cjs/loader:787:27)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\sqlite3-binding.js:4:17)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\snapshot\\highu\\OneDrive\\Masaüstü\\XXX\\node_modules\\sqlite3\\lib\\sqlite3-binding.js',
'C:\\snapshot\\highu\\OneDrive\\Masaüstü\\XXX\\node_modules\\sqlite3\\lib\\sqlite3.js',
'C:\\snapshot\\highu\\OneDrive\\Masaüstü\\XXX\\.\\.\\.\\.\\.js'
],
pkg: true
}
Node.js v18.5.0

I cannot launch React app on Windows. I have some problems with React

I have a problem with launching react application on Windows 10. For that reason, I used command npx create-react-app . and unfortunately, I received the following bug:
Error: Child compilation failed:
Module build failed (from ../../c#/artur/node_modules/html-webpack-plugin/lib/loader.js):
Error: Cannot find module 'C:\Users\Dell\Desktop\c#\artur\node_modules\html-webpack-plugin\lib\loader.js'
Require stack:
- C:\Users\Dell\Desktop\c#\artur\node_modules\loader-runner\lib\loadLoader.js
- C:\Users\Dell\Desktop\c#\artur\node_modules\loader-runner\lib\LoaderRunner.js
- C:\Users\Dell\Desktop\c#\artur\node_modules\webpack\lib\NormalModule.js
- C:\Users\Dell\Desktop\c#\artur\node_modules\webpack-manifest-plugin\dist\index.js
- C:\Users\Dell\Desktop\c#\artur\node_modules\react-scripts\config\webpack.config.js
- C:\Users\Dell\Desktop\c#\artur\node_modules\react-scripts\scripts\start.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 loadLoader (C:\Users\Dell\Desktop\c#\artur\node_modules\loader-runner\lib\loadLoader.js:19:17)
at iteratePitchingLoaders (C:\Users\Dell\Desktop\c#\artur\node_modules\loader-runner\lib\LoaderRunner.js:182:2)
at runLoaders (C:\Users\Dell\Desktop\c#\artur\node_modules\loader-runner\lib\LoaderRunner.js:397:2)
at NormalModule._doBuild (C:\Users\Dell\Desktop\c#\artur\node_modules\webpack\lib\NormalModule.js:812:3)
at NormalModule.build (C:\Users\Dell\Desktop\c#\artur\node_modules\webpack\lib\NormalModule.js:956:15)
at C:\Users\Dell\Desktop\c#\artur\node_modules\webpack\lib\Compilation.js:1367:12
ModuleBuildError: Module build failed (from ../../c#/artur/node_modules/html-webpack-plugin/lib/loader.js):
Error: Cannot find module 'C:\Users\Dell\Desktop\c#\artur\node_modules\html-webpack-plugin\lib\loader.js'
My setup:
Node version: 16.13.1 LTS
Npm version: 8.3.0
I'm new in the world of front-end development, and I don't know why that happens. I found similar bugs on the Internet, but these answers didn't work for me.

Apollo-server tutorial from GraphQL website produce error

I can't get this tutorial to work (running on Ubuntu v19.04):
https://www.apollographql.com/docs/apollo-server/getting-started/
My code is literally copy+pasted from the tutorial - I have installed all dependencies, and I keep getting the following error when running node index.js:
internal/modules/cjs/loader.js:628
throw e;
^
Error: No valid exports main found for '{project-path}/node_modules/uuid'
at resolveExportsTarget (internal/modules/cjs/loader.js:625:9)
at applyExports (internal/modules/cjs/loader.js:502:14)
at resolveExports (internal/modules/cjs/loader.js:551:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:657:22)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:960:27)
at Function.Module._load (internal/modules/cjs/loader.js:855:27)
at Module.require (internal/modules/cjs/loader.js:1033:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> ({project-path}/project-myra/node_modules/apollo-engine-reporting/dist/agent.js:26:16)
at Module._compile (internal/modules/cjs/loader.js:1144:30) {
code: 'MODULE_NOT_FOUND'
This is literally so frustrating, because the only place to get any help with apollo-server is from a Spectrum chat that keeps disconnecting, and doesn't even allow me to create any posts...
Why is this library the official supported and recommended library for GraphQL? And how come I seem to be the only person in the world having this issue, I can't find anyone else asking about this...
It seems it's a problem with the current Apollo Server version.
Try downgrading to 2.6.3, this worked for me. Haven't tried with any other version though.
npm install apollo-server#2.6.3

I get a SyntaxError in Node.JS, but I can't figure out the origin of that error from the log messages

I am running a Node app on Azure. It's a Web API and when I try to call it, I see this message in the Node console:
Application has thrown an uncaught exception and is terminated:
SyntaxError: Unexpected token (
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (D:\home\site\wwwroot\app.js:17:23)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
I ran my whole code through eslint and didn't find any syntax errors. It also runs fine on my local machine, but doesn't run on Azure.
The message above points to line 17 and column 23 in app.js, which is a require:
let warehouseExport = require('./routes/warehouse-export-api');
I ran eslint and jshint specifically on the file referenced above, and there are no syntax errors.
What are some other ways I can get the exact location of the syntax error, and why could it be that the code fails on Azure but runs on my local machine?
What I tried:
Wrap in try-catch and grab the line number - it shows up undefined:
try {
var warehouseExport = require('./routes/warehouse-export-api');
} catch (error) {
console.log(error + ', line ' + error.lineNumber);
}
You should check version of nodejs you have installed on Azure. Maybe it's <= 4 and it doesn't support let keyword. Just a wild guess.
The cause of the error was that the Node version somehow got reset to 4.2.4.
When I go to Azure Portal and run node --version, I get version 8.1.4.
However, if I console.log the Node version inside my script, it is somehow still 4.2.4.
I will investigate why that happened and how to fix it, but for now it's clear that the bug is due to async function not being recognized by the old Node.
Update: the package.json file where the node version was specified got overwritten somehow, which is what caused the issue.

Unable to preview / run angular.js project from codenvy

I developed an angular.js project on codenvy IDE on Javascript framework ( or is it platform). I am unable to preview the same.
I get the following error.
[ERROR] Failed to start application. : ====> /logs/stderr.log <==== node.js:134 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: Cannot find module 'gulp' at Function._resolveFilename (module.js:326:11) at Function._load (module.js:271:25) at require (module.js:355:19) at Object.(/var/vcap.local/dea/apps/app-07zsn86eb8vspvg0-0-bf2638b3e702ededc5473a0c16608d37/app/gulpfile.js:1:74) at Module._compile (module.js:411:26) at Object..js (module.js:417:10) at Module.load (module.js:343:31) at Function._load (module.js:302:12) at Array. (module.js:430:10) at EventEmitter._tickCallback (node.js:126:26)
The console output says it cannot find Gulp, but my project certainly has gulp.js on the root folder. Also the project works perfectly fine when i preview this from a Webstorm editor - so i dont think there is an issue with the code per se..
Any help much appreciated
James
If your project is public, please, share it with Codenvy's factory feature. So everyone will be able to look what is wrong with the project. (You can access factory on left panel of the IDE)

Categories