I have created an npm package which has a lot of dependencies, but when I test my app with npm install -g ./ the app gets added in the global npm directory but without the node-modules folder. Thus when the app is run through the terminal, although the app is recognized, it doesn't work because none of the dependency is installed.
How can I make sure to make app installs node-modules when its published in the npm registry
If I install the node-modules independently on the project folder by doing npm install, the app works. I don't want the user to install the packages independently. What I am expecting is the full installation of the app and the required dependencies only with npm install -g my_package
I have also used yarn as the package manager, and the dependencies are listed under "dependencies" in package.json file. The "bin" field in the package.json file points to our app, which can also be run as node bin/index.js. This app is also recognized by the terminal, the only problem is the dependencies
I think you can use this command npm install --save then it might work.
Related
How are packages installed with the command
$ npm i -g <package_name>
different from the packages installed with the following command?
$ npm i <package_name>
The main difference between the locally installed and globally installed packages is that
locally installed packages are kept inside the same directory that you run the npm install <package_name> and these packages are kept in the node_modules folder under that same directory.
globally installed packages are all kept in the same directory(the exact location depends upon your system setup). These packages are kept in the same directory regardless of where you run the npm install -g <package_name> from.
Generally, it is suggested to install packages locally since updating a global package causes every application using that specific package to use the updated package and you might have to do the maintainence work, which is basically a nightmare.
Locally installed packages are installed under node_modules folder. They are not accessible by other npm projects you have. Each npm project, initialized with npm init, has its own node_modules folder.
On the other hand, globally installed packages are installed in the same folder of your system.
When you import a package with
require('package-name');
You're importing it from your local packages under node_modules.
It's advisable to avoid installing packages globally. Usually, you only install global packages when they provide CLI functionalities (Scripts that you run from you terminal, using bash, shell, etc).
I want to install react-native cli but I don't where to run this command: npm install -g react-native-cli. Do I need to run this command on my macOS terminal or when I will make a directory for my react native app then there I need to run this command in vscode?
Is there any issue if I run this command in my terminal or If I run this in VScode?
React Native is distributed as two npm packages, react-native-cli and react-native.
The first one is a lightweight package that should be installed globally (npm install -g react-native-cli), while the second one contains the actual React Native framework code and is installed locally into your project when you run react-native init.
Because react-native init calls npm install react-native, simply linking your local GitHub clone into npm is not enough to test local changes.
npm install –g react-native-cli
· This line installs the npm package react-native-cli along with its dependencies(from the npm repository host) inside the globally shared node_modules folder.
· Global install (with -g): puts stuff in /usr/local or wherever node is installed. This will also allow you to access the module from the command-line, as the bin is symlinked into a PATH folder (usually usr/local/bin).
Refer below link
https://rlogicaltech.medium.com/how-to-install-react-native-on-mac-step-by-step-guide-1ac822aedd4f
You can run the command anywhere in the terminal.
It will install the react-native-cli globally as we are specifying the "-g" option in the command.
Use this
npm install -g expo-cli
this how I solved it.
npm install -save react-native#latest
When I npm install package, npm says that it successfully installed the package, but when I look for it in the node_modules folder, the package is not in the folder. When I npm install -g package, the package gets installed into the global /node_modules folder, so I have to drag the package from the global folder to the local folder.
Why is npm install not installing into my local /node_modules folder?
step 1) rm -rf ./node_modules from your root directory.
step 2) npm install.
The above commands first deletes your node_modules and then reinstalls all the packages that are found inside your package.json.
This is the same problem I was facing, both the above commands resolved the problem in my case.
If the above solution does not work in your case :
The problem is :
Data is not being fetched from the package.json, you must check whether you have written the correct statement or not inside your package.json.
There are a few things you can do to resolve this problem, as mentioned here.
First, try deleting your package-lock.json file. If you run npm install or npm i after that it should generate a brand new installation with no reference to an existing package-lock.json file.
If that doesn't work, try deleting your node_modules directory in your project. Then run npm install or npm i.
If THAT doesn't work, you should try deleting both the node_modules directory AND the package-lock.json. Then run npm install or npm i. This should resolve the issue.
I have a asp.net core react app and using webpack for bundling .I have installed required dependencies but when build application it shows an error.
How could i resolve this error.
I have installed required dependencies so many times done npm cache clean and restarted a machine.still its showing not installed in vs solution explorer.
webpack installed in requied folder.
IN vs solution
when try to restore package inside solution explorer,its not installed.
webpack-cli is missing
You doing wrong in your npm install
Should be this command for global
npm i -g webpack-cli
or this command for local
npm i -D webpack-cli
You can not mix up between -D -g flag
If that didn't work for you try to right click on that package and click restore
Update:
Try to delete package-lock.json then run npm i -D webpack-cli again
So I navigated to my project directory and run npm install scrollama intersection-observer. It installed the files on my HOME/node-modules instead of the project folder. During installation there were warnings, though:
npm WARN saveError ENOENT: no such file or directory, open '[my-home]/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '[my-home]/package.json'
npm WARN [my-user] No description
npm WARN [my-user] No repository field.
npm WARN [my-user] No README data
npm WARN [my-user] No license field.
So why did it installed globally (or, in my home instead of my project folder)?
Because your folder is not a valid npm install location as it could not find the package.json. to create that, just run:
npm init
You are not using npm init. npm init will initialize your node project and will make a package.json file. package.json file will store the information about the project such as project name, version, description and also the dependencies you download.
In your case there is no package.json file, because of this your packages are been installed to the home directory instead of current directory.
Also you can also use parameters like -g to install package globally (to the home directory) without any parameter, node will install the package in the current directory by default.
Installing locally: you can use the package inside your project.
Installing globally: you can use the package everywhere. Commands like nodemon are installed globally because you want to use these in every project.