Bun 1.2完全ガイド2025 - 次世代JavaScriptランタイムの新機能
Bun 1.2の革新的な新機能を徹底解説。ビルトインPostgresクライアント、S3サポート、3倍高速化したExpress、新しいロックファイル形式など、開発効率を劇的に向上させる最新アップデートを実践例とともに紹介。
Bun 1.1が今週リリース。「npm/yarn/pnpmの完全互換」を謳うBunで、実際に既存プロジェクトを動かしてみた結果、衝撃の速さと意外な落とし穴を発見。
Bun 1.1 がリリースされました!「npmや yarn の 5 倍速い」という触れ込みを見て、即座に試してみました。
結論:速さは本物、でもまだ完璧じゃない。
実際のプロジェクト(依存関係 200 個)で測定:
7 倍以上速い!これは体感できるレベルの違いです。
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
sudo npm install -g パッケージ名
sudo を使うとパーミッションがおかしくなることがあるので、できるだけ避けましょう。 私は一度これで環境を壊しました…
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-app@1.0.0
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR! react@"^18.2.0" from the root project
パッケージ間の依存関係が解決できない。npm v7 以降で厳密になった。
npm install --legacy-peer-deps
npm install --force
rm package-lock.json
rm -rf node_modules
npm install
私は最初、方法 3 で解決することが多かったです。
npm ERR! network request to https://registry.npmjs.org/express failed, reason: connect ETIMEDOUT
npm ERR! network This is a problem related to network connectivity.
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
# 中国のミラーを使う例
npm config set registry https://registry.npmmirror.com
npm config set fetch-timeout 60000
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit
ネイティブモジュールのビルドに必要なツールがない。
xcode-select --install
管理者権限で PowerShell を開いて:
npm install --global windows-build-tools
sudo apt-get install build-essential
私は macOS で Xcode のアップデート後によくこのエラーに遭遇します。
npm ERR! enoent ENOENT: no such file or directory, open '/Users/username/project/package.json'
package.json がないディレクトリで npm install を実行した。
# プロジェクトのルートディレクトリに移動
cd /path/to/project
# または新規プロジェクトなら初期化
npm init -y
恥ずかしながら、これは今でもたまにやります。
Error: Cannot find module 'node-sass'
Require stack:
- /Users/username/project/node_modules/sass-loader/dist/utils.js
node-sass のバージョンと Node.jsのバージョンが合わない。
npm uninstall node-sass
npm install node-sass
npm uninstall node-sass
npm install sass
node-sass は本当にトラブルが多いので、可能なら sass(Dart Sass)への移行がおすすめです。
npm ERR! cb() never called!
npm ERR! This is an error with npm itself.
npmのキャッシュが壊れている。
npm cache clean --force
これで解決しない場合は、npmのバージョンを更新:
npm install -g npm@latest
npm install でエラーが出ると本当にイライラしますよね。
でも、大抵のエラーは誰かが既に遭遇していて、解決方法も存在します。 このページが少しでも役に立てば幸いです。
新しいエラーに遭遇したら、随時追加していきます。