👌

「yarnとnpmの混在 & yarn installが遅すぎ」を解消

2023/07/05に公開

概要

nodejs コンテナの立ち上がりが妙に遅いなと思ったらこんな表示を発見したので解消

package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.

要は「npm と yarn が混在してるよ」というエラー

まずは混在を解消

単純に package-lock.json を削除して yarn install してみたがだめ

https://registry.npmjs.org/@mui/icons-material/-/icons-material-5.11.16.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOENT: no such file or directory, chmod '/workspace/.cache/yarn/v6/npm-@mui-icons-material-5.11.16-integrity/node_modules/@mui/icons-material/esm/AirlineStopsSharp.js'"

yarn.lock を削除して再度実行

https://registry.yarnpkg.com/@types/node/-/node-20.3.3.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOENT: no such file or directory, open '/workspace/.cache/yarn/v6/npm-@types-node-20.3.3-329842940042d2b280897150e023e604d11657d6-integrity/node_modules/@types/node/ts4.8/dgram.d.ts'"

これで混在は解消できた

yarn install が毎度遅すぎるので解消

この記事を参考
https://zenn.dev/tamanugi/articles/6f372d45b85c18
devcontainer 内で yarn install の実行速度がかなり早くなった

volumes:
  node_modules:

services:
  app:
    build:
      args:
        - NODE_VER=18.16.0-slim
      context: ./docker
      dockerfile: Dockerfile
    tty: true
    volumes:
      - type: bind
        source: ./
        target: workspace
      - type: volume
        source: node_modules
        target: workspace/node_modules
    command: /bin/bash -c "yarn install && yarn dev"
    working_dir: workspace
    ports:
      - 5173:5173

途中で発生したエラー

Dockerfile の CMD で yarn install を実行したら以下のエラーが発生
結局解消できず compose.yml の command で実行することで妥協
Dockerfile と compose.yml でなぜ権限が変わるのだろう・・・
ホスト内とコンテナで権限が異なったりするらしいが解消できなかった

error An unexpected error occurred: "EACCES: permission denied, mkdir '/workspace/app/node_modules/acorn'".
info If you think this is a bug, please open a bug report with the information provided in "/workspace/app/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

参考

GitHubで編集を提案

Discussion