我应该如何解决在编译资产(Laravel Mix)时发生的错误

时间:2018-11-13 15:20:40

标签: php laravel sass laravel-mix

我对 PHP 并不陌生,但是我是PHP框架的初学者。 最近,我开始学习 PHP Laravel 框架,因此我决定从Traversy Media频道的教程开始。在尝试编译资产后,出现错误:(在npm run dev之后发生错误

ERROR in ./node_modules/css-loader??ref--5-2!./node_modules/postcss-loader/lib??postcss!./node_modules/resolve-url-loader??ref--5-4!./node_modules/sass-loader/lib/loader.js??ref--5-5!./resources/sass/app.scss
Module build failed: BrowserslistError: Unknown browser query `basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")`
    at C:\xampp\htdocs\myapp\node_modules\browserslist\index.js:164:11
    at Array.reduce (<anonymous>)
    at resolve (C:\xampp\htdocs\myapp\node_modules\browserslist\index.js:132:18)
    at browserslist (C:\xampp\htdocs\myapp\node_modules\browserslist\index.js:224:16)
    at Browsers.parse (C:\xampp\htdocs\myapp\node_modules\autoprefixer\lib\browsers.js:61:16)
    at new Browsers (C:\xampp\htdocs\myapp\node_modules\autoprefixer\lib\browsers.js:52:30)
    at loadPrefixes (C:\xampp\htdocs\myapp\node_modules\autoprefixer\lib\autoprefixer.js:70:24)
    at plugin (C:\xampp\htdocs\myapp\node_modules\autoprefixer\lib\autoprefixer.js:81:24)
    at LazyResult.run (C:\xampp\htdocs\myapp\node_modules\postcss\lib\lazy-result.js:277:20)
    at LazyResult.asyncTick (C:\xampp\htdocs\myapp\node_modules\postcss\lib\lazy-result.js:192:32)
    at processing.Promise.then._this2.processed (C:\xampp\htdocs\myapp\node_modules\postcss\lib\lazy-result.js:231:20)
    at new Promise (<anonymous>)
    at LazyResult.async (C:\xampp\htdocs\myapp\node_modules\postcss\lib\lazy-result.js:228:27)
    at LazyResult.then (C:\xampp\htdocs\myapp\node_modules\postcss\lib\lazy-result.js:134:21)
    at Promise.resolve.then.then (C:\xampp\htdocs\myapp\node_modules\postcss-loader\lib\index.js:145:8)
    at <anonymous>
 @ ./resources/sass/app.scss 4:14-254
 @ multi ./resources/js/app.js ./resources/sass/app.scss

I am trying to solve this problem but without success. I have tried to rebuild node-sass, also I've tried to reinstall all dependencies and change my @import path and nothing solved an error.
This is the code that refers to an error that occurs in **C:\xampp\myapp\node_modules\browserslist\index.js:164:11**

Resolve function for referring error

如果您能帮助我,我将不胜感激,因为我确实需要加快学习过程。

npm -v 6.1.0
节点-v 8.11.3
作曲者-v 1.7.2
artisan --version(Laravel Framework)5.7.13

1 个答案:

答案 0 :(得分:0)

如果npm install在您的根项目中生成了很多文件
转到C:\ user {您的名字}并清空.npmrc文件(您会发现prefix =某些内容)

第二,我通过删除node_modules和

来解决此问题。
"browserslist": [
        "last 3 versions"
    ],

在我的package.json中。

您再次运行npm install和npm run watch或dev