yarn - What does #npm mean? - material-ui

I know that running yarn add package#1.2.3 would install package v1.2.3.
I recently encountered this syntax: yarn add package#npm. What does #npm do? Is it a special sign for yarn or is it specific to that package (material-ui)?
I encountered #npm as a solution to include two versions of material-ui by aliasing the next version: yarn add material-ui-next#npm:material-ui#next

No real surprises, it is a directive to install a specific package from npm.
yarn add {package1} installs the specified package from the npm registry by default.
yarn add {package1}#npm:{package2} installs package2 from the npm registry and assigns package1 as its alias.
It makes no difference if a package named package1 exists in the npm registry, it will only download the package you've specified with the #npm directive.
From your question, it seems like you've already got a handle on this one.

Related

NPM: skip dev dependencies when installing a package from Github

Is it possible to exclude dev dependencies when installing directly from GitHub?
Unfortunately the command
npm install --only=production my-repo#github:path-to/my-repo
doesn't seem to work, it only excludes dev dependencies specified in the current package.json file, not the ones specified in the package I am installing.

Using Sails.js with yarn

When I run sails new myapp it generates a package.json file and a /node_modules directory. The sails docs say to cd in and run npm install to get up and running.
I've recently started using yarn and would like to use it to manage the additional dependencies I add to my sails app. However, when I run yarn init (what I think creates the yarn.lock file) it looks like it wants to create my package.json again. And it errors on the entry point question, saying Cannot convert object to primitive value.
Should I just stick to vanilla npm? Can Yarn and Sails play nicely in the sandbox together and share the toys?
In fact, $ yarn init (as well as $ npm init) will just initialize your package.json file by asking a few questions.
Here you don't need to regenerate your package.json but just install your node modules and generate a yarn.lock file to lock your modules versions. You can do this by using $ yarn install or just $ yarn.
You can skip $ yarn init as it does the exact same thing as $ npm init. $ yarn install actually creates the yarn.lock file. Unlike npm, yarn actually respects the engines property in a package.json file. If you run into this you can use $ yarn install --ignore-engines.

Ionic 1.x - from bower to npm

I used to install plugins in my ionic 1 project with bower. The new trend, especially with ionic 2, is to install packages with npm. Some core packages, such as ionic.cloud are not provided at all anymore with bower, even for ionic 1.x.
So I need to migrate some packages to npm. What is the recommended way to do so ?
My problem:
"npm install" seems to install packages in the "my_project/node_modules" folder, unlike bower which installs packages directly in my_project/www/lib/
As explained for instance in the installation guide of ionic.cloud this requires an additional step to copy the newly installed npm package in the lib folder with the command:
cp node_modules/#ionic/cloud/dist/bundle/ionic.cloud.min.js www/lib
However, when I update the package and run "npm update", this will update the node_modules folder, but not the lib folder. This is a problem as only the files from my lib folder are included in my index.html.
Running the cp-command after each npm update does not seem such an elegant solution. What is the recommended way to deal with this?
I think you can reverse this make the .bowerrc file create your packages inside the node_modules folder and use this path as default. Otherwise the node_modules is mandatory there is no way around creating it.
Even you can npm i --prefix ./bower_components/ <package> you still need to cp to folders up from bower_components folder

Install specific branch from github using Npm

I would like to install bootstrap-loader from github in my project using npm
Currently they are maintaining two version of this project which are comaptible with webpack version 1 and 2.
I would like to install version 1. What npm command I should use to install this?
I tried using below one but it is not working.
npm install git://github.com/shakacode/bootstrap-loader.git[#v1] --Save
There are extra square brackets in the command you tried.
To install the latest version from the brach-name branch, you can use:
npm install "https://github.com/shakacode/bootstrap-loader.git#branch-name" --save
npm: npm install username/repo#branchName --save
yarn: yarn add username/repo#branchName
e.g. npm i betimer/rtc-attach#master --save (my username is betimer)
// this will appear in your package.json:
"rtc-attach": "github:betimer/rtc-attach#master"
One thing I also want to mention: it's not a good idea to check in the package.json for the build server auto pull the change. Instead, put the npm i (first command) into the build command, and let server just install and replace the package.
One more note, if the package.json private is set to true, may impact sometimes.
you can give git pattern as version, yarn and npm are clever enough to resolve from a git repo.
yarn add any-package#user-name/repo-name#branch-name
or for npm
npm install --save any-package#user-name/repo-name#branch-name
Another approach would be to add the following line to package.json dependencies:
"package-name": "user/repo#branch"
For example:
"dependencies": {
... other dependencies ...
"react-native": "facebook/react-native#master"
}
And then do npm install or yarn install
I'm using SSH to authenticate my GitHub account and have a couple dependencies in my project installed as follows:
"dependencies": {
"<dependency name>": "git+ssh://git#github.com/<github username>/<repository name>.git#<release version | branch>"
}
Had to put the url in quotes for it work
npm install "https://github.com/shakacode/bootstrap-loader.git#v1" --save
Tried suggested answers, but got it working only with this prefix approach:
npm i github:user/repo.git#version --save -D
Only solution working for me:
$ npm i https://github.com/{USER}/{REPO}/tarball/{BRANCH} --save
as explained here.
Both below versions work for me as of beginning of 2023:
npm i "github:shakacode#bootstrap-loader"
npm i "https://github.com/shakacode/tree/bootstrap-loader/"
The Doc of the npm defines that only tag/version can be specified after repo_url.
Here is the Doc: https://docs.npmjs.com/cli/install

How to compile and run an ES6 file with node when using babel6?

I installed the latest version 6 of babel, babel-core and babel-loader.
How can I run an ES6 file in Node with Babel6?
Previously I would run the command
babel-node server.js
but now I get this message:
The CLI has been moved into the package `babel-cli`. See http://babeljs.io/docs/usage/cli/.
None of the instructions on that page say how to do this.
The message could be clearer. You've installed the babel package and you should have installed the babel-cli package.
npm uninstall babel
npm install babel-cli
Upon installing babel-cli I also had to specify the es2015 loader and to specifically use my local babel-node package since I don't have it installed globally.
./node_modules/.bin/babel-node --presets es2015 server.js