NPM and Bower how to use both for the same pacakge - npm

I have some libraries that I want available for my front end Bower packages and my back end NPM packages. Is there are way to handle this without creating 2 sets of packages in both Bower and NPM?

Get rid of bower, and use only NPM. Here is a good read:
https://www.quora.com/Why-use-Bower-when-there-is-npm

Related

how do i add yarn package to react native project installed with npm?

Note: Do guide me if something is missing.
So, I wanted to install a package from https://rnfirebase.io/auth/usage, but I have an npm project. The command on the website has only for yarn. I don't want to add yarn to project because (Is there any harm in using NPM and Yarn in the same project?) it states that it is not recommended.
So, then how do I install it with npm?
You have to use yarn, or you can look for a package that has the functions that you are looking for using npm
You can install it with npm just fine, don't worry. They are all package managers installing npm packages from the same repository. There is no difference in what you are installing or how they are installed. You can get different node_module structures, but for yarn you need config for that.
Yes its not recommended because it generates different lockfiles that will dictate different structures and versions in your node_modules folder. You want multiples devs to have the same "experience". However, lots of JS frameworks will come pre-configured with yarn, like React Native and you just end up having two lockfiles. One for npm and one for yarn. There is no harm in deleting the yarn file and keeping the package-lock. If you delete both, a new lockfile for the package manager you are using will be generated on npm i | yarn i | pnpm anyway.
To install it with npm just use npm i <PACKAGE_NAME> so npm i #react-native-firebase/app.
Here is the npm repo page for that package, https://www.npmjs.com/package/#react-native-firebase/app, notice the install command is npm! Only reason firebase devs only mention yarn is because they are hipsters ;)

How do I force npm to reinstall a single package, even if the version number is the same?

In my Node.js project, I have a dependency on another local project. Oftentimes, I need to make a small change to the dependency and see how it affects my main project. In order to do this, I have to reinstall my dependency using npm.
I can use npm update to try to update my dependency, but this seems like it will only work if the version number has changed on the dependency. I don't want to have to change the version number on my dependency every time I change a line of code or two to make an experimental change in development.
I can rm -rf node_modules/; npm install to ensure that I get the latest versions of all of my dependencies. Downloading all of my non-local dependencies takes several minutes, breaking up my train of thought.
Is there a way to force npm to reinstall a single dependency, even if that dependency's version number hasn't changed?
When you run npm install, it will install any missing dependencies, so you can combine it with an uninstall like this:
npm uninstall some_module; npm install
With npm 5, uninstalled modules are removed from the package.json, so you should use:
npm uninstall some_module; npm install some_module
On npm v 6.14:
npm install module_name --force --no-save
You get a message stating:
npm WARN using --force I sure hope you know what you are doing.
And then it proceeds to uninstall and reinstall the package.
Note: if you don't specify the --no-save option, npm updates the package version on package.json to the highest version that is compatible with the existing SemVer rule.
If you do not want npm to update the package's version on package.json, keep the --no-save option.
Not the best answer, but just for information, you can run
npm ci
It is the same as npm install, but it will remove the existing node_modules folder, if any, and do a fresh install for all packages. This is useful if the files in node_modules have been changed for some reason and you want to revert them to their original state.

Bower versus npm - I need npm to install bower

I'm looking to properly set up a small demo in my git repo for public demo.
I've used both bower and npm before, though they weren't my decision.
My codebase is front-end only, so after doing a little reading, I thought bower would make more sense than npm.
Turns out I need npm just to install bower. How is this making things simpler for me at all?

Why do NPM node modules contain a bower.json file?

I've been tasked with removing bower where possible and instead using NPM to install modules. I've done a search of the codebase and the only bower.json files are within NPM node modules. I thought that NPM was an alternative to bower, is this incorrect?
I was expecting to find a bower.json file in the project root. As I haven't does it should like NPM is already being used instead?
You can use NPM as an alternative to bower, yes.
Every module has a bower.json because the module wants to support bower and npm as well. Module managers can write stuff like version number, ignore certain files to download, etc. You don't need to worry about these files.
Your package doesn't have a bower.json - perfect. You don't support bower.

Why npm has newer version of packages than bower

I am using ng-prettyjson in my project. For dependencies management I am using bower.
After setting dependency to the ng-prettyjson to the next one "ng-prettyjson": "~0.1.6", I am receiving information
> bower not-cached git://github.com/darul75/ng-prettyjson.git#~0.1.6
> bower resolve git://github.com/darul75/ng-prettyjson.git#~0.1.6
> bower ENORESTARGET No tag found that was able to satisfy ~0.1.6
>
> Additional error details: Available versions: 0.1.3, 0.1.1
If you check on ng-prettyjson github page it is true - only 2 releases, but if you take a look into ng-prettyjson npm repository there is 0.1.6. as the latest version. What is more if you try to install this component with npm you will install 0.1.6 version.
Is there any way to instruct bower to use as well npm repository for searching dependencies? Does it make sense to do such a thing?
You cannot instruct bower to do this. This is because Bower will need additional information about the bower component (like dependencies, version, etc.). This information is needed to resolve the dependencies in your bower-components folder.
Most dependencies have build automation to update their bower and npm repositories, so I think you will not always get this problem. If you really need the most recent version of prettyjson, you could use npm for this specific dependency, or ask the developer to update it's bower repository.
I have just released a new version, thank you for warning me about it, you can download version here or with bower.
0.1.6 release