\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
in my local Project javascript file, I typed the code const cowsay = require("cowsay"), when i try to run the node "index.js", again produced the error: Cannot find module cowsay
Finally used the command node link cowsay, the error is:
*node:internal/modules/cjs/loader:1078
throw err;
^
Error: Cannot find module 'F:\Web Development\JavaScript\Node\Jokester\link'
at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
at Module._load (node:internal/modules/cjs/loader:920:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.16.0*
I was trying to install cowsay package globally and run it in my local Project using npm link <module_name> but the following error is thrown:
*node:internal/modules/cjs/loader:1078
throw err;
^
Error: Cannot find module 'F:\Web Development\JavaScript\Node\Jokester\link'
at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
at Module._load (node:internal/modules/cjs/loader:920:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.16.0*
The issue you are running into stems from incorrect link
command.
Instead of node link ...
run npm link ...
.
Here are the proper steps to link a globally installed module for use in a local project:
cowsay
module:npm install -g cowsay
cowsay
:npm link cowsay
NOTE linking is done using
npm
cli which usesnodejs
This will symlink the global module into your local node modules folder, but usually you don't need to link global modules, they are automatically found. You might have to reinstall your nodejs.