Node can't find npm's dependent modules after unpacking binary tarball - node.js

I downloaded the latest Node LTS Linux x86 binary tarball from here:
https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-x86.tar.xz
And extracted it here:
/home/paul/dev/node-v8.12.0-linux-x86
I added Node's bin/ directory to my path:
$ echo $PATH
/home/paul/dev/node-v8.12.0-linux-x86/bin:/usr/local/bin:/usr/bin:/bin
And Node runs fine:
$ node -v
v8.12.0
However, when running npm, which is bundled with the Node binary tarballs, I get this:
$ npm -v
module.js:550
throw err;
^
Error: Cannot find module 'semver'
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> (/home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules/npm/lib/utils/unsupported.js:2: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)
Enabling module's debugging shows the paths it is searching for to find the semver module:
MODULE 19001: Module._load REQUEST semver parent: /home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules/npm/lib/utils/unsupported.js
MODULE 19001: looking for "semver" in ["/home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules/npm/lib/utils/node_modules","/home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules/npm/lib/node_modules","/home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules/npm/node_modules","/home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules","/home/paul/dev/node-v8.12.0-linux-x86/node_modules","/home/paul/dev/node_modules","/home/paul/node_modules","/home/node_modules","/node_modules","/home/paul/.node_modules","/home/paul/.node_libraries","/home/paul/dev/node-v8.12.0-linux-x86/lib/node"]
In there I see this path:
/home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules/npm/node_modules
Which is where the semver module lives (as a dependent module of npm):
$ ls -al /home/paul/dev/node-v8.12.0-linux-x86/lib/node_modules/npm/node_modules/semver
total 80
drwxr-xr-x 3 paul paul 125 Sep 29 11:01 .
drwxr-xr-x 351 paul paul 12288 Sep 10 15:23 ..
drwxr-xr-x 2 paul paul 27 Sep 10 15:23 bin
-rw-r--r-- 1 paul paul 765 Feb 10 2018 LICENSE
-rw-r--r-- 1 paul paul 1598 Aug 17 17:42 package.json
-rw-r--r-- 1 paul paul 619 Aug 17 17:42 range.bnf
-rw-r--r-- 1 paul paul 14655 Aug 17 17:42 README.md
-rw-r--r-- 1 paul paul 36503 Aug 17 17:42 semver.js
So why can't Node resolve the semver module for npm?
For fun, I tried the latest 9.x release that supports x86, and it still fails, but gives a different message:
$ node -v
v9.11.2
$ npm -v
internal/modules/cjs/loader.js:550
throw err;
^
Error: Cannot find module '/home/paul/dev/node/bin/npm'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
at Function.Module._load (internal/modules/cjs/loader.js:475:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
Something is definitely up with Node's module resolution.
Thanks!
-Paul

I was having same problem with create-react-app
I don't know how but adding 'sudo' worked for me.
$ npm start
---> Giving Error same as yours
$ sudo npm start
---> Work Perfectly
hope it solve your problem

Related

"Error: Cannot find module '#app/foo'" in prod mode when using libs

I have a project where I built several modules. After finding that nestjs has a lib cli command I ported all of them to use this style.
Now my app can't find these modules when using npm run start:prod.
Error: Cannot find module '#app/foo'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/xxx/Development/nest-test/dist/src/app.service.js:13:15)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
I created a project with the basic code and one library to reproduce the problem: https://github.com/hkeio/nestjs-test
Even when I link the package node is not able to find the module.
cd libs/foo
npm link
cd ../..
npm link #app/foo
When running NODE_DEBUG=* npm run start:prod I can see that he is looking at the right place but does not find the module:
MODULE 12494: looking for "#app/foo" in [
"/Users/xxx/Development/nest-test/dist/src/node_modules",
"/Users/xxx/Development/nest-test/dist/node_modules",
"/Users/xxx/Development/nest-test/node_modules",
"/Users/xxx/Development/node_modules",
"/Users/xxx/node_modules",
"/Users/node_modules",
"/node_modules",
"/Users/xxx/.node_modules",
"/Users/xxx/.node_libraries",
"/Users/xxx/.nvm/versions/node/v10.15.3/lib/node"
]
...
$ pwd
/Users/xxx/Development/nest-test/node_modules
$ ll #app
total 0
drwxr-xr-x 3 xxx staff 96 May 30 09:04 .
drwxr-xr-x 608 xxx staff 19456 May 30 09:04 ..
lrwxr-xr-x 1 xxx staff 65 May 30 09:04 foo -> ../../../../.nvm/versions/node/v10.15.3/lib/node_modules/#app/foo```
According to the docs of tsconfig-paths it can be used when executing the built sources with node.
The issue comment you are referencing also mentions execution with node.
Actually the problem occurs when executing the built files with node dist/main.js, not during the build process with tsc.
I managed to get a working solution by following theses instructions from tsconfig-paths docs. #bisonfoutu created an example repo here.
Add a file named tsconfig-paths-bootstrap.js to the root of the project, and paste the code from the docs in it.
Change the start:prod script to: node -r ./tsconfig-paths-bootstrap.js dist/main.js
You should now be able to compile and execute the project with TS paths. (be aware that you will not be able to compile if there is no path set in tsconfig.json)

Error: libopencv_dnn.so.3.4: cannot open shared object file when using node-opencv

I'm using the opencv library for Node, and am running into some weird path issue on Linux
When simply issuing require('opencv');, I get the following error:
Error: libopencv_dnn.so.3.4: cannot open shared object file: No such file or directory
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
I looked at binding.gyp and if I execute the find-opencv.js utility I get what seems to be a sane answer:
/usr/src/app/node_modules/opencv# node utils/find-opencv.js --libs
-L/usr/local/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
I can see opencv_dnn in there, and if I ls the libs directory:
ls -l /usr/local/lib | grep dnn
lrwxrwxrwx 1 root root 20 Mar 20 17:23 libopencv_dnn.so -> libopencv_dnn.so.3.4
lrwxrwxrwx 1 root root 22 Mar 20 17:23 libopencv_dnn.so.3.4 -> libopencv_dnn.so.3.4.5
-rw-r--r-- 1 root root 12970608 Mar 20 17:20 libopencv_dnn.so.3.4.5
I see that libopencv_dnn.so.3.4 definitely exists.
Not really sure what my next step is here...
OK, so running ldconfig seemed to "fix" the issue
You have two option actually:
1- Use LD_LIBRARY_PATH to point to OpenCV build libs
export LD_LIBRARY_PATH=/usr/src/app/build/lib
2- Easy way is to use ldconfig

node.js ftdi module throws error: libftd2xx.so: cannot open shared object file

I installed the Linux-ARM-FTDI Drivers 1.1.12 like in the readme-file described:
http://www.ftdichip.com/Drivers/D2XX/Linux/ReadMe-linux.txt
and also successfully tested the EEPROM/read-example to check the installation and it gives me a correct output of my USB device. I then got some trouble at first installing the ftdi package because ftd2xx.h was not found. I followed this description: https://forum.sparkfun.com/viewtopic.php?p=50378
and after copying ftd2xx.h and WinTypes.h to /usr/loacl/include I could install ftdi via npm without a problem.
Now when I try to require ftdi:
var ftdi = require('ftdi');
I get the following error:
/home/utilite/node/usb_socket/node_modules/ftdi/node_modules/bindings/bindings.js:83
throw e
^
Error: libftd2xx.so: cannot open shared object file: No such file or directory
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 bindings (/home/utilite/node/usb_socket/node_modules/ftdi/node_modules/bindings/bindings.js:76:44)
at Object.<anonymous> (/home/utilite/node/usb_socket/node_modules/ftdi/index.js:3:31)
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)
Here are the dependecies:
ls -l /usr/local/lib/libftd2xx.*
-rw-r--r-- 1 root root 241478 Jun 16 14:17 /usr/local/lib/libftd2xx.a
lrwxrwxrwx 1 root root 34 Jun 16 14:18 /usr/local/lib/libftd2xx.so -> /usr/local/lib/libftd2xx.so.1.1.12
-rwxr-xr-x 1 root root 229597 Jun 16 14:17 /usr/local/lib/libftd2xx.so.1.1.12
utilite#utilite-ubuntu-desktop:~/node/usb_socket$ ldd /usr/local/lib/libftd2xx.so
libpthread.so.0 => /lib/arm-linux-gnueabi/libpthread.so.0 (0x401ff000)
libdl.so.2 => /lib/arm-linux-gnueabi/libdl.so.2 (0x400c0000)
librt.so.1 => /lib/arm-linux-gnueabi/librt.so.1 (0x400ae000)
libgcc_s.so.1 => /lib/arm-linux-gnueabi/libgcc_s.so.1 (0x40013000)
libc.so.6 => /lib/arm-linux-gnueabi/libc.so.6 (0x4021a000)
/lib/ld-linux.so.3 (0x4002d000)
looks ok for me.
The Targt-System:
Linux utilite-ubuntu-desktop 3.0.35-cm-fx6-4 #123 SMP Thu Sep 12 10:41:30 IST 2013 armv7l armv7l armv7l GNU/Linux
node.js version: 0.10.22 (highest 0.10.x version to run on the target)
Any suggestions?
is /usr/local/lib in your linker path?
I don't think /usr/local/lib is linked in by default in new versions of ubuntu.
ldconfig /usr/local/lib/
to add it to the linker cache and test.
should add it to a .conf file /etc/ld.so.conf.d/ if this solves your problem.
https://unix.stackexchange.com/questions/67781/use-shared-libraries-in-usr-local-lib
I'm not experienced with node, but can you run ldd on the executable (not on the library) ? It might show that libftd2xx.so is not found, hence the error.
It might have something to do with the compile flags (and the rpath pointing to /usr/local/lib). Have a look at this related answer

Nodeclipse + nodemon error

When I try to run an express app in nodeclipse, it gives me the error,
23 Jan 11:58:04 - [33m[nodemon] v1.0.13[39m
23 Jan 11:58:04 - [33m[nodemon] to restart at any time, enter rs[39m
23 Jan 11:58:04 - [33m[nodemon] watching: .[39m
23 Jan 11:58:04 - [32m[nodemon] starting node
/home/rdteam/workspace/NedvedNodeExpressTest/app.js[39m
[31m[nodemon] unable to run executable: "node"[39m
However, when I run from command line that
node /home/rdteam/workspace/NedvedNodeExpressTest/app.js
or
nodemon /home/rdteam/workspace/NedvedNodeExpressTest/app.js
both work without problem.
Pls help.
Regards
Hammer
In my case (running os x) I quick solved it setting the full path in :
/usr/local/lib/node_modules/nodemon/lib/monitor/run.js
function run(options) {
var cmd = config.command.raw;
//Added line
cmd.executable = '/usr/local/bin/node';
I was able to solve this problem by using the forever module, and configuring Nodeclipse's 'Node monitor path' to point to forever (*../npm/node_modules/forever/bin/forever*)
npm install forever
Open Eclipse -> Preferences -> Nodeclipse
Set the 'Node monitor path' to your installation of forever, and you're done.
I ran headlong into this problem whilst setting up Nodeclipse, and getting my node programs to work on Eclipse Kepler running on Mac OS X 10.8.5 (Mountain Lion)
The use case "Nodeclipse with nodemon":
Nodeclipse 0.9 Eclipse 4.2.2 Java 1.7 on win32
Configure Nodeclipse with monitor path C:\Users\weibl\AppData\Roaming\npm\node_modules\nodemon\nodemon.js
logilog.js with console.log('done');
Run As -> Node with monitor
Produced command line (seen in Nodeclipse Console):
node --harmony C:\Users\weibl\AppData\Roaming\npm\node_modules\nodemon\nodemon.js D:\Workspaces\ADT-Bundle\CountingServer\try\logilog.js
Console output
23 Jan 16:23:35 - [33m[nodemon] v0.7.10[0m
Error: ENOENT, no such file or directory 'D:\Workspaces\ADT-Bundle\CountingServer\try\undefined\nodemonCheckFsWatch1390465415226'
at Object.fs.openSync (fs.js:427:18)
at Object.watchFileChecker.check (C:\Users\weibl\AppData\Roaming\npm\node_modules\nodemon\nodemon.js:154:22)
at ready (C:\Users\weibl\AppData\Roaming\npm\node_modules\nodemon\nodemon.js:49:22)
at testAndStart (C:\Users\weibl\AppData\Roaming\npm\node_modules\nodemon\nodemon.js:71:5)
at Object.<anonymous> (C:\Users\weibl\AppData\Roaming\npm\node_modules\nodemon\nodemon.js:847:1)
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 Function.Module.runMain (module.js:497:10)
23 Jan 16:23:35 - [33m[nodemon] to restart at any time, enter `rs`[0m
23 Jan 16:23:35 - [32m[nodemon] watching: D:\Workspaces\ADT-Bundle\CountingServer\try[0m
23 Jan 16:23:35 - [nodemon] exception in nodemon killing node
Created issues #118 https://github.com/Nodeclipse/nodeclipse-1/issues/118
That is how issues are reported.
Thank you for letting know that you need this. Check http://www.nodeclipse.org/ on news and how to help.
If you create a nodemon.json config file in your application folder (e.g. /home/rdteam/workspace/NedvedNodeExpressTest/nodemon.json) with the following JSON it should work without having to modify the Nodemon source files.
{
"exec": "/usr/local/bin/node"
}
This work on OS X, you may need to change the path depending on where you have node installed.
Details on Nodemon config files:
https://github.com/remy/nodemon#config-files

Error: Cannot find module './lib/socket.io'

I had my server working with an earlier version of node.js, npm, and socket.io but after updating I started getting issues with socket.io:
$ node server.js
node.js:237
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module './lib/socket.io'
at Function._resolveFilename (module.js:333:15)
at Function._load (module.js:280:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object.<anonymous> (/usr/local/lib/node_modules/socket.io/index.js:8:18)
at Module._compile (module.js:444:26)
at Object..js (module.js:462:10)
at Module.load (module.js:351:32)
at Function._load (module.js:309:12)
at Module.require (module.js:357:17)
Before upgrading I had a symlink for socket.io under node_modules pointing to the "centrally installed" directory with the same name. Recently I tried installing socket.io local to my project by issuing the command:
npm install socket.io
which placed socket.io under node_modules in my project. I found it strange at first that the error message was saying "./lib/socket.io" but when I looked into it I found that project/node_modules/socket.io/index.js is requiring socket.io like so:
module.exports = require('./lib/socket.io');
But there is nothing there except transport:
...project/node_modules/socket.io/lib
$ ll
total 24
drwxrwxr-x 3 ghbarratt dev 4096 Mar 26 14:38 .
drwxrwxr-x 5 ghbarratt dev 4096 Mar 26 15:03 ..
-rw-rw-r-- 1 ghbarratt dev 10777 Mar 6 16:37 transport.js
drwxrwxr-x 3 ghbarratt dev 4096 Mar 26 14:38 transports
Should there be another socket.io directory or a socket.io.js file under lib? Why would index.js be requiring an internal file that seems to be missing?
Versions:
node -v
v0.7.7-pre
npm -v
1.1.12
socket.io#0.9.2
Distributor ID: Ubuntu
Description: Ubuntu 10.10
Release: 10.10
Codename: maverick
I hate to answer my own question, but I did get things resolved and there were no other answers so I am going to add this in case it can help someone else.
With Felix Loether's comment (which I +1ed) I was fairly certain that I did not get all the files I should have during the npm install socket.io. I tried doing an apt-get update/upgrade, thinking that I might need an update for tar or something, but the results were still the same.
I was noticing a 304 response in the install output and wondered at that point if there was some sort of npm cache that I should try clearing. I discovered I could clear the npm cache with the command: npm cache clean. Cleaning the cache finally got me past the no-errors-until-runtime issue.
I then started to get an error message: make: node-waf: Command not found which lead me to reinstall node.
And after all that, it worked!

Resources