Node cannot find installed package - node.js

I have a simple nodejs client that uses grpc and protobuf to talk to a cpp grpc server.
My package.json contains the required packages:
"dependencies": {
"google-protobuf": "^3.9.1",
"grpc-web": "^1.0.6",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.7"
}
I ran npm install and all the modules were installed in locally node_modules.
My client in in the same path as node_modules but when I launch it, I get an error saying that it cannot find the protobuf module.
From client.js:
var messages = require('../../messages/proto/output/work_pb.js');
var services = require('../../messages/proto/output/work_grpc_web_pb.js');
var grpc = require('grpc');
Running the client:
node client.js
Error: Cannot find module 'google-protobuf'
Require stack:
- /home/work/messages/proto/output/work_pb.js
- /home/work/frontend/web/client.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:713:15)
at Function.Module._load (internal/modules/cjs/loader.js:618:27)
at Module.require (internal/modules/cjs/loader.js:771:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/home/radu/work/admass/messages/proto/output/work_pb.js:11:12)
at Module._compile (internal/modules/cjs/loader.js:868:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:879:10)
at Module.load (internal/modules/cjs/loader.js:731:32)
at Function.Module._load (internal/modules/cjs/loader.js:644:12)
at Module.require (internal/modules/cjs/loader.js:771:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/work/messages/proto/output/work_pb.js',
'/home/work/frontend/web/client.js

Removing the entire node_modules folder and re-installing will work:
rm -rf node_modules
npm install

I ended up adding the node module inside '../../messages/ and removing it from pace where the proto files are being referenced, as to avoid conflicts.

Related

No definite solution on Windows for Cannot find module 'graceful-fs' Error on React Native App Create Start Up

`PS C:\Users\Adrien\Documents\ReactNativeProjects> npx react-native start
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'graceful-fs'
Require stack:
- C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\gracefulifyFs.js
- C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\bin.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at _gracefulFs (C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\gracefulifyFs.js:15:39)
at Object.<anonymous> (C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\gracefulifyFs.js:22:1) at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Adrien\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\tools\\gracefulifyFs.js',
'C:\\Users\\Adrien\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\bin.js'
]
}
Node.js v18.13.0
Everytime I tried to create an App I got this as a response.
I tried to Open a Project like,
npx react-native init App2
I was expecting was for the project to get built, appear so that I could see all the project files.
I tried uninstalling and then reinstalling like,
npm install 'graceful-fs'
I tried the other solutions here too like apt-get or sudo and curl but it didn't work in my terminal`

NodeJS nodegui module could not be found

Attempting to get nodegui running on a blank nodeJS project, but it won't run. The example starter-project runs fine, however I do not want to use webpack on my project.
Error when running node main.js:
internal/modules/cjs/loader.js:1208
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: The specified module could not be found.
\\?\C:\Users\user\Documents\project\node_modules\#nodegui\nodegui\build\Release\nodegui_core.node
�[90m at Object.Module._extensions..node (internal/modules/cjs/loader.js:1208:18)�[39m
�[90m at Module.load (internal/modules/cjs/loader.js:1002:32)�[39m
�[90m at Function.Module._load (internal/modules/cjs/loader.js:901:14)�[39m
�[90m at Module.require (internal/modules/cjs/loader.js:1044:19)�[39m
�[90m at require (internal/modules/cjs/helpers.js:77:18)�[39m
at Object.<anonymous> (C:\Users\user\Documents\project\node_modules\�[4m#nodegui�[24m\nodegui\dist\lib\utils\addon.js:3:15)
�[90m at Module._compile (internal/modules/cjs/loader.js:1158:30)�[39m
�[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)�[39m
�[90m at Module.load (internal/modules/cjs/loader.js:1002:32)�[39m
�[90m at Function.Module._load (internal/modules/cjs/loader.js:901:14)�[39m
main.js:
const { QMainWindow } = require("#nodegui/nodegui");
const win = new QMainWindow();
win.show();
global.win = win;
When running npm install #nodegui/nodegui this is the output.
Windows 10 x64 build 18363, NodeJS version 12.16.1, NPM version 6.14.2, NodeGUI version 0.16.0
npx qode main.js
or
npm exec qode main.js
It's seem specified module is missing in your project you need to run:
npm i --save specified

Google Cloud Function not recognizing Papaparse 5.0 Dependency

I am building a Node.js Google Cloud function, and it is not recognizing the dependency "papaparse":
in package.json
"dependencies": {
"papaparse": "^5.0.0",
"twilio": "^3.33.2"
}
Error code I am getting:
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'papaparse'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/index.js:8:14)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
I have tried reinstalling papaparse, running npm audit, but those steps haven't helped.
Does anyone know why this would happen?
I just managed to deploy a Cloud Function with papaparse.
For this you just need to deploy your function from the Cloud Shell. First create a folder where you gonna insert all your files. Then clone the repo from the papaparse github with the command git clone into that folder.
Now after adding your Index.json and your Package.json you can deploy your Cloud Function following this Deploying from Your Local Machine documentation.

Error running Gulpfile from Visual Studio 2015 task runner

I am building a gulpfile to use in my aps.net winforms project. So far I have the following in the package.json
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"browserify": "^13.1.0",
"del": "2.2.0",
"gulp": "^3.9.1",
"gulp-sourcemaps": "^2.2.0",
"gulp-typescript": "^3.0.2",
"tsify": "^2.0.2",
"vinyl-source-stream": "^1.1.0"
}
}
and the gulp file has
/// <binding BeforeBuild='default' />
/*
This file in the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007
*/
var gulp = require('gulp');
var del = require('del');
var ts = require("gulp-typescript");
var tsProject = ts.createProject("tsconfig.json");
var sourcemaps = require('gulp-sourcemaps');
gulp.task('default', function () {
// place code for your default task here
});
My node version is 6.9.1
If I run this from the command line ('gulp') it works fine. But in the Visual Studio task runner, it fails to load, and in the out put I see the following error. This error starts after I add the line var sourcemaps = require('gulp-sourcemaps');
Failed to run "H:\dev\myproj\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
H:\dev\myproj\node_modules\gulp-sourcemaps\node_modules\strip-bom\index.js:2
module.exports = x => {
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (H:\dev\myproj\node_modules\gulp-sourcemaps\src\init.js:10:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Also adding var tsify = require("tsify"); I get another error...
Failed to run "H:\dev\myproject\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
TypeError: Object #<Object> has no method 'debuglog'
at Object.<anonymous> (H:\dev\myproject\node_modules\tsify\index.js:4:32)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (H:\dev\myproject\gulpfile.js:17:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Anyone have any ideas why I am getting this?
Thanks in advance!
My problem was I didn't realize Visual Studio has it's own (way out of date) version of the node tools (installed within the Visual Studio folders somewhere). How untidy!
To make it use the "global" node tools, I could go to the menu Tools | Options | Projects and Solutions | External Web Tools and move the $(PATH) to be before the $(DevEnvDir)\* locations. After I did this, my Gulp file would load.
The other option may have been to update the Visual Studio node tools via the Tools | Extensions and Updates, but (I think) I'd prefer to use the same external tools I will use outside of Visual Studio.
After some investigate with me facing the same issue, it seems to be a problem with version compatibility between your nodejs install, and your package dependency "strip-bom".
An adhoc fix is to change from:
module.exports = x => {
to:
module.exports = function (x) {
You might want to check this out:
Gulp-Sourcemaps, SyntaxError: Unexpected token >
That seems to solve the issue for me, but not such a nice method.
The problem is that you might be running an old version of node. Try to use the command node -v or nodejs -v to check your version.
Though it might not be your case, but great for others to come by and see this, Debian/Ubuntu actually has an an outdated version of node on its package manager "apt-get". So it is highly possible that you're still running an old version such as 0.10.25.
The real fix I'd recommend (which I ended up doing), is to upgrade your node version. As of current date, version 6.9.1 seems to be the latest stable.
You can check the install guide at the nodejs official website here:
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Error: Cannot find module './proto' on Heroku

I can't seem to figure out why this works locally fine, but when I push it to Heroku it fails with the following error.
Error from Heroku
Starting process with command `node web.js`
module.js:337
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module './proto'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (/app/node_modules/express/node_modules/connect/lib/connect.js:14:13)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
Process exited with status 1
State changed from starting to crashed
package.json
{
"name": "divtest",
"version": "0.0.2",
"dependencies": {
"underscore": "1.3.x",
"crypto": "0.0.x",
"knox": "0.3.x",
"mongoose": "~3.1.2",
"mime": "1.2.x",
"express": "3.0.x",
"request": "~2.9.203"
},
"engines": {
"node": "0.6.x",
"npm": "1.0.x"
}
}
./proto is a local module that connect is calling
I've blown away my ./node_modules folder and did a npm install --save and still get the same results.
I had this issue, and my problem was that I'm a git beginner and hadn't properly committed all of the files that were needed. It looks like there was a proto.js in connect somewhere.
I did a git add * (...) and pushed again and it all went nicely.
Another telling error, was that on push Heroku complained about unmet dependencies.

Resources