1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

dockerを使ったlaravelで'npm run watch'コマンドが使えない時の解決例

1
Last updated at Posted at 2020-05-04

どんな状況

npm run watchを使って自動的にscssをコンパイルさせようと思ってコマンドを打ったところ下記のようなエラーが出ました

 % npm run watch
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/user/projects/construction_management_system/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/user/projects/construction_management_system/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user/.npm/_logs/2020-05-04T07_12_15_852Z-debug.log

原因

コマンドを打つディレクトリを間違っていました。(筆者はエラーの三行目を見て気がつきました。)

こうなった理由はdockerを使用する時にローカルのディレクトリをsrcという名前で一つ下げているのですが、それに気づかなかったためプロジェクトの一番上のディレクトリでこのコマンドを打ってしまい上記のエラーが出てしまいました。

解決方法

srcにディレクトリを変えて、同じコマンドを打つことでエラーを解消することができました。(下記の手順)

% cd src
% npm run watch

余談

artisanのコマンドを打つ時大抵はdocker-compose exec phpをつけていると思うのですがこのコマンドはローカルのファイルを変えるコマンドなので特につけなくていいみたいです

あとlaravelの使い方として、コンパイルして Users/user/construction_managment_system/src/public/css/app.cssを呼び出してトップページに反映させられなくて苦しんだのですが、下記の呼び出しのコマンドを使うことで無事反映させることができました。

Users/user/construction_managment_system/src/resources/views/welcome.blade.php
~前略~
<link rel="stylesheet" href="{{ asset('css/style.css') }}">
~後略~

cssの当て方を解決してくれた記事が気になる方はこちらをご参照ください

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?