17
12

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.

[Laravel-mix] npm run dev で sh: cross-env: command not found

Last updated at Posted at 2017-08-31

環境

CenntOS 7.3
Laravel 5.5(5.4でも同じエラーになる)
PHP 7.1.9
npm 3.10.10
node 6.11.1

WindowsのDirをDocker環境にmountしてるので
--no-bin-links つけてます。

注)2017/8/31時点での成功例です。

現象

npm run dev
実行時に「sh: cross-env: command not found」となる。

2017/8/21の時点では
npm install cross-env --save-dev --no-bin-links
で良かったのに、8/30にはダメになってた。

手順

  1. node npm install
yum
sudo yum install -y nodejs npm https://kojipkgs.fedoraproject.org//packages/http-parser/2.7.1/3.el7/x86_64/http-parser-2.7.1-3.el7.x86_64.rpm
  1. project作成
composer
composer create-project laravel/laravel:5.5.* --prefer-dist mix
  1. mix環境作成

■ package.json のdevDependenciesから "cross-env": "^5.0.1", を削除

shell
cd mix
vi package.json             [devDependenciesからcross-envを削除]
npm -g install cross-env cross-spawn [globalに入れる]
npm install --no-bin-links  [npm ERR! Maximum call stack size exceededとなる]
npm install --no-bin-links  [再度実行]
npm rebuild --no-bin-links  [ERRになったのでrebuild]
npm run dev                 [DONE Compiled successfullyとなる筈]

※npm install --no-bin-links 実行時にパーミッションエラーになったら
キャッシュがよくないみたいですので全部消してやり直しました。

shell
npm cache clean
rm -Rf ~/.npm
rm -Rf ./node_modules

追記:cross-spawnも必要でした。

参照
CentOS 7.3でyum install nodejsが失敗するので回避する
Compile assets with Laravel Mix Error on Laravel 5.4 and Node.js
Laravel 5.4 'cross-env' is not recognized as an internal or external command

17
12
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
17
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?