發佈日期: 發佈留言

指令 疑難雜症 整理

各種指令 php、 mysql、 composer、 npm、 Vue等等,輸入後遇到的問題解決方式。

點下面節點可快速到達該區塊:

{ php/ mysql/ composer }

Q: php artisan migrate 後出現 Illuminate\Database\QueryException : could not find driver

A: 原因是 php.ini 擴充套件 “php_pdo_mysql.dll”、extension=pdo_sqlite 沒開啟

Q: Cannot create cache directory /Users/.composer/cache/repo/https—repo.packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /Users/.composer/cache/files/, or directory is not writable. Proceeding without cache
Cannot create cache directory /Users/.composer/cache/repo/https—repo.packagist.org/, or directory is not writable. Proceeding without cache

A: 原因是沒權限寫入或新增 cache,輸入以下指令:
sudo chown -R $USER $HOME/.composer

Q: php artisan serve 後出現 file_put_contents(C:\xampp\htdocs\lsapp\storage\framework/sessions/亂碼): failed to open stream: No such file or directory.

A: 表示原本的 cache 沒清空,輸入以下指令:
php artisan route:cache
php artisan cache:clear
php artisan config:cache
php artisan view:clear

Q: php artisan serve 後出現 Please provide a valid cache path.

A: storage/framework/ 下加上3個資料夾:session、views、cache

Q: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

A: mysqld stop
mysql.server start

Q: composer 後出現 Cannot create cache directory .. or directory is not writable. Proceeding without cache in Laravel

A: 原因是沒權限寫入或新增 cache,輸入以下指令:
sudo chown -R $USER $HOME/.composer

Q: No available formula with the name “mariadb.”

A: 重開 mariadb 試試看。
brew services stop mariadb
Stopping `mariadb`… (might take a while)
==> Successfully stopped `mariadb`

brew services start mariadb
==> Successfully started `mariadb`

Q: Warning: require_once(/function/System_DB_mysqlClass.php): failed to open stream: No such file or directory in D:\work\Project\CompanyWebsite\2013\Dev\Php+Html\config.inc.php on line 136

Fatal error: require_once(): Failed opening required ‘/function/System_DB_mysqlClass.php’ (include_path=’.;C:\php\pear’) in D:\work\Project\CompanyWebsite\2013\Dev\Php+Html\config.inc.php on line 136

A: 通常是檔案的相對位置錯誤,放對就好了。

Q: php artisan serve 後出現 PHP Warning: require(/Users/doublin/Projects/doublin_icon/vendor/autoload.php): failed to open stream: No such file or directory in /Users/doublin/Projects/doublin_icon/artisan on line 18

A: 通常是 composer 沒有完整安裝所造成。
$ composer install
$ composer update

Q: php artisan serve 後出現 Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes) in phar:

A: 查詢 php 記憶體限制
$ php -r “echo ini_get(‘memory_limit’).PHP_EOL;”
提升到無限制
$ composer_memory_limit =-1

Q: php artisan serve 後出現 Deprecated: Return type of Illuminate\Container\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset)

A: 你電腦環境的 php 跟你專案所使用的 php 不相容。


{ Git }

Q: git push 後出現
To https://github.com/你的repository.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://github.com/你的repository.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

A: 因為線上版本的內容比你電腦裡要推上去的檔案還要新,所以 Git 不讓你推上去。
1. 先拉合併檔案再推:
$ git pull
$ git merge
拉完最新版本檔案後,查看哪邊要合併的合一合就推上去囉!
$ git push

2. 強制推:
$ git push -f
但會覆蓋掉最新版本,小心使用。

{ npm }

Q: php artisan migrate 後出現 Cannot create cache directory /Users/doublin/.composer/cache/repo/https—repo.packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /Users/doublin/.composer/cache/files/, or directory is not writable. Proceeding without cache
Cannot create cache directory /Users/doublin/.composer/cache/repo/https—repo.packagist.org/, or directory is not writable. Proceeding without cache

A: composer dump-autoload -o
composer update

Q: npm run watch 後出現 Module not found: Error: Can’t resolve ‘axios’ in

A: npm install –save axios

Q: npm run watch 後出現 Error: spawn node_modules\webpack\bin\webpack.js ENOENT

A: npm install && npm run dev

Q: npm run dev 後出現 EPERM: operation not permitted, open ‘放置槽:\你專案位置\public\js\app.js’

A: npm install && npm run dev

Q: npm install 後出現 found 8 vulnerabilities (4 moderate, 4 high)

A: run `npm audit fix` to fix them, or `npm audit` for details

Q: npm run watch 後出現 ‘cross-env’ 不是内部或外部命令,也不是可運行的程序

A: 是因為 mac, windows 不相容的關係
npm install cross-env –save-dev

Q: npm run watch 後出現系統找不到指定的路徑
events.js:174
throw er; // Unhandled ‘error’ event
^

A: 是因為 webpack.js 不見的關係
npm install –save-dev webpack

Q: npm run watch 後出現 error cannot find module webpack.config.js

A: 是因為 webpack.config.js 不見的關係
npm install laravel-mix –save-dev
npm i -g create-webpack-config

Q: npm run watch 後出現 [webpack-cli] Unknown argument: –hide-modules

A: Laravel Mix 是 Laravel 提供的 JavaScript 和 CSS 編譯工具
npm install laravel-mix@6.0.0-beta.4 -D

Q: npm run watch 後出現
Vue packages version mismatch:
– vue@3.1.1 (C:node_modules\vue\index.js)
– vue-template-compiler@2.6.14 (C:node_modules\vue-template-compiler\package.json)
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

A: 是因為 vue 跟 vue-template-compiler 不同版本才有錯誤。
– 用 vue2 : 就直接去 package.json 把 vue 跟 vue-template-compiler 改為同版本後,移除 node_modules 、package-lock.json 後下指令 npm install 更新。
– 用 vue3 : 要多安裝 laravel-mix-vue3 、@vue/compiler-sfc、vue-loader

Q: npm run watch 後出現 Node events.js:167 throw er; // Unhandled ‘error’ event

A: 移除 node_modules、package-lock.json 後 npm install

Q: npm run watch 後出現 1 WARNING in child compilations (Use ‘stats.children: true’ resp. ‘–stats-children’ for more details)

A: 在 webpack.mix.js 中加入
mix.webpackConfig({
stats: {
children: true,
},
});

Q: npm run watch 後出現 You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file

A: 以下兩種擇一試試看
1. mix.js(‘resources/js/app.js’, ‘public/js’).vue() 最後加上 .vue()
2. npm install vue-template-compiler vue-loader@ –save-dev –legacy-peer-deps

Q: npm run prod 後出現 [webpack-cli] Error: Unknown option ‘–no-progress’

A: 因為 Webpack 5 CLI 移除一堆選項,所以用 laravel-mix 6 的要去 package.json 更新 script
原本的 script

"scripts": {
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "npm run development -- --watch",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
}

更新後的 script

"scripts": {
    "development": "mix",
    "watch": "mix watch",
    "watch-poll": "mix watch -- --watch-options-poll=1000",
    "hot": "mix watch --hot",
    "production": "mix --production"
}

{ Vue }

Q: [Vue warn]: Unknown custom element: <notification> – did you register the component correctly? For recursive components, make sure to provide the “name” option

A: Vue 註冊 component 的只能小寫


{ 未分類 }

Q: Illuminate\Database\Eloquent\MassAssignmentException: Add [name] to fillable property to allow mass assignment on [App\Contact].

A: model 中加上 protected $guarded = [];

Q: PDOException: SQLSTATE[HY000]: General error: 1 table contacts has no column named name

A: 因為 table 中沒有此欄位 ,加上$table->string(‘name’);

Q: Missing required parameters for [Route: login] [URI: {language}/login].

A: 可能是 Kernel.php 裡的路徑位置擺錯

Q: init.bat 後出現 init.bat : The term ‘init.bat’ is not recognized as the name of a cmdlet, function, script file, or operable program. C
heck the spelling of the name, or if a path was included, verify that the path is correct and try again.

A: 依照建議提示改成對的路徑 $ .\init.bat

Q: vagrant up 後出現 check your homestead.yaml (or homestead.json) file the path to your private key does not exist

A: 需產生 ssh 開放金鑰,在 homestead 資料夾中,右鍵 Git bash,輸入 ssh-keygen,按兩次enter,就好了

Q: mysql 後出現 ‘mysql’ is not recognized as an internal or external command,
operable program or batch file

A:

Q: Missing required parameters for Route

A: Route 裡的值要傳好 <a href=”{{ route(‘user.settings’, auth()->user()->nickname) }}”>Settings</a>

Q: 點不同頁面都一直被導去某特定頁面?

A: 找出 login 控制
app\Http\Middleware\CheckLoginStatus.php
裡註解下面那段,可以不會一直被導走
$path_contains_login = (strpos($request->path(), ‘login’) !== false)
~
return redirect()->to(‘/’);

Q: 網站更新後也清除 cache,還是有 cache 住?

A: 在引入 css、js 的程式碼後加上 ?v=’. time()
範例:
<link href=”{{ asset(‘css/app.css?v=’. time()) }}” rel=”stylesheet”>

Q: Use of undefined constant info – assumed ‘info’

A: @{{ info }} ,雙中括號前加上@


發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *