「npm」タグアーカイブ

【海外記事】NPM vs Yarn Cheat Sheet 日本語訳(npm と yarnの違い)

%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88-2016-10-21-20-27-22
あなたはyarnという新しいJavaScriptパッケージマネージャーを聞いた事あって、その使い方を知りたい
でしょう。
NPMを知っているならもうほとんどの部分は設定されています。

ここではスイッチする際の注意点をお伝えします。

Cheat Sheet — What you need to know
知っておくべき事

・npm install === yarn

インストールはデフォルトの振る舞いです。

・npm install taco --save === yarn add taco

Tacoパッケージはすぐさまpackage.jsonに保存されます。

・npm uninstall taco --save === yarn remove taco

--save は「npm config set save true」によってNPMのなかでデフォルトとされています。
ただし、これは大抵の開発者にたいして明示的にされていません。
package.jsonからの追加と削除はYarnではデフォルトです。

・npm install taco --save-dev === yarn add taco --dev

・npm update --save === yarn upgrade

アップデート対アップグレードがあります、それらは正確には
それが何をしているか。
バージョン番号が動き、アップグレードは何か起こる!

注意 npm update --save は3.11で壊れているようです。

・npm install taco@latest --save === yarn add taco

・npm install taco --global === yarn global add taco

あなたがすでにyarnについて知っています

パッケージは同じNPMレジストリー上のものです
yarnは基本的にNPM構造とレジストリーが同じ新しいインストーラーです。

・npm init === yarn init

・npm link === yarn link

・npm outdated === yarn outdated

・npm publish === yarn publish

・npm run === yarn run

・npm cache clean === yarn cache clean

・npm login === yarn login (and logout)

・npm test === yarn test

yarnはNPMが持っていない事を持っています

・yarn clean

警告を出すアイテムを飛ばします

・yarn licenses ls

あなたの依存のライセンスを覗き見る事を可能にします

・yarn why taco

tacoパッケージがインストールされている理由、他のパッケージがそれに依存する詳細をみる

・早いです

※たしかにインストールが早い

・yarn lockfileで自動的なシュリンクラップ

依存するバージョンを固定することができる

ここから脱線して調べた事↓
※npm shrinkwrapとの違い(npm shrinkwrapとはなにかはここ)
・デフォルトで生成されるので簡単に利用できる
・各モジュールがソートされており構成管理が容易ということ
(より依存モジュールのバージョン記載のファイルが見やすく、それはデフォルトで生成されるようになったってことですね。)

・Security-centric designです

(後で調べる)

NPMができてyarnがもっていないこと
・npm xmas === **NO EQUIVALENT**
・npm visnup === **NO EQUIVALENT**

ちょっと深掘りしてみますーー

ではーーー

【Error】node-sassが怪しい | fs.js:856 return binding.readdir(pathModule._makeLong(path));でたら

久しぶりに動かしたプロジェクトでgulp叩いたらエラー出てた。
fs.js:856 return binding.readdir(pathModule._makeLong(path));
スタックトレース追っていったらnode-sassとかから出ているみたい。

ここ参考に、
やっていることはインストールしなおしているようなので、依存関係おかしくなっているのかな。。

npm i -D node-sass

tslintもエラー出てたら
npm i -D tslint

動いた。
これから腕まくりします。

でわーーーーーーーー

【TypeScript】sh: tsc: command not found (npm run build時)

npm run buildした際にこういうのでたら

sh: tsc: command not found

▀ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/Cellar/node/6.2.2/bin/node" "/usr/local/bin/npm" "run" "tsc"
npm ERR! node v6.2.2
npm ERR! npm v3.9.5
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! an2_ts_playgrond@1.0.0 tsc: `tsc -p .`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the an2_ts_playgrond@1.0.0 tsc script 'tsc -p .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the an2_ts_playgrond package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc -p .
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs an2_ts_playgrond
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls an2_ts_playgrond
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR! /Users/No51/Desktop/Git/angu2_type/an2_ts_playgrond/npm-debug.log
▀ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/Cellar/node/6.2.2/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v6.2.2
npm ERR! npm v3.9.5
npm ERR! code ELIFECYCLE
npm ERR! an2_ts_playgrond@1.0.0 build: `npm run tsc && npm run browserify`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the an2_ts_playgrond@1.0.0 build script 'npm run tsc && npm run browserify'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the an2_ts_playgrond package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run tsc && npm run browserify
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs an2_ts_playgrond
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls an2_ts_playgrond
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR! /Users/No51/Desktop/Git/angu2_type/an2_ts_playgrond/npm-debug.log
[an2_ts_playgrond]

--------------------------

sh: tsc: command not found

これ。
tscがコマンドでパス通っていない可能性大
npm install tsc

をやってみてください。
npm のグローバルのパスが通っていればうまくいくはずです。

【npm】npm i でpackageのバージョン指定、上げたくない時

npm i で勝手にバージョン上勝手しまうことがあります。
それは
package.jsonのバージョン指定が

fafafa : ^2.5.0

とかになっているからです。
この場合もし2.5.1とかバージョンが上がったら
npm installで上がってしまいます。

もしnpm i でpackageのバージョン指定、上げたくない時

npm install --save --save-exact [packagName]

とやるといいです、

npm config ls -l
とやってみてください。
npm の設定が見れます。

【npm】npm i でpackageのバージョン指定、上げたくない時
【npm】npm i でpackageのバージョン指定、上げたくない時

そこに書いてある
save=true
save-exact=true

はnpm i 時に自動でそれをオプションなしでやってくれます。
もしfalseになっていたら

ターミナルで
npm config set save=true
npm config set save-exact=true

をしてください。
npm config ls -l
でtrueになったことを確認してください。

これでオプションなしで、表題のことをやってくれます。

でわまたー