I've created my first NodeJS module using lodash. When I install my module using npm i mymodule --save and run my index.js script using require('lodash') I get an error with a sub module...
Error : Error: Cannot find module 'lodash'
lodash is well installed but not in the root directory, in the modules directory...
In the source tree of your module you need to run:
npm install lodash --save
And then publish a new version of your module to npm.
The package.json of your module needs to have lodash in its dependencies. If it doesn't then it will not get installed together with your module.
Related
I installed a public github repo using the syntax provided in the repository's readme:
npm install https://github.com/user_name/proj_name.git
However, I'm not sure how to load this module into my js code. I've tried:
const my_lib = 'proj_name';
Unfortunately, this is not working for me. How can I load a module that was installed directly from a github repository?
Currently you're just defining a constant as a string with value 'proj_name'.
To load a module from node_modules, you have to do the following:
npm install <package_name> --save, where --save write the package and version in your dependencies of package.json. You can also use --savedev to write the package in your devDependencies (both optional).
Use const packageName = require('packageName'); in your e.g. app.js to use the package in your code.
See here for more details about npm install in general, specifying-dependencies and here for ecma script require and import.
I just started project react native. I created react native module by command npm install react-native-my-library --save, then run npm install I see it exist in node_module folder.
But when I change code in react native module, and remove folder node_module and run npm install again to update in node_module, it also doesn't update new code that I changed in native module.
Any body can help me to update code in node module folder.
Thanks so much!
i have ng-sidebar module for my app but when i install new module like ng2-d&d:
npm install ng2-dnd --save
old module remove from app-module and following error occurres :
Cannot find module ng-sidebar.
i tried to find ng-sidebar in node module but i I didn't find it.i install ng-sidebar.
npm install ng-sidebar --save
but last module that i install missed from node-module.
first i delete package-lock.json and then i go to root directory i write npm update in command and now it's working
I am working in VSCode on Ubuntu 16.04. I've created node project using below commads:
npm init
tsc --init
I've created a new file called index.ts. I'm trying to use fs and readling to read file contents. but when I am writing below lines of code at the top of index.d.ts:
import fs = require('fs');
import readline = require('readline');
I'm getting below error:
can not find module 'fs' and can not find module 'readline'
even process is not found.
I've installed typings of node from here using below command:
sudo npm install #types/node -global --save
Can anyone please help me how to resolve this error?
Since TypeScript 2.x, all typings are installed using npm like this: npm install #types/node.
For TypeScript 1.8, it might be better to typings to install the node types. For detail see the quickstart at: https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html.
For what i know you have two options here:
(Recommended) Install devDepencencie npm install #types/node --save-dev, which will add the type module for http.
Create a index.d.ts file declaring a definition for http module, like:
declare module 'http. This method will not enable auto-complete for http methods
I am trying to run a pre developed example in node.js environment. But i keep on getting the following error:
Cannot find module '/build/default/validation'
Am I missing some module installation from npm here...? I have installed all the other modules like socket-io, websocket, websocket-server, websocket-clien, etc.
-Parag
Check the package.json file for all required modules. Run npm install and npm update to automatically install all required modules and update them.
Usually, npm modules are in a folder *node_modules*, so /build/default/... looks like some custom module that should be shipped with the example.