【问题标题】:Laravel scss compiling failsLaravel scss 编译失败
【发布时间】:2018-01-20 22:41:28
【问题描述】:

我正在尝试学习 laravel 并在 Windows 10 上使用 composer 建立一个新项目

如果我尝试编译

资源\资产\sass\app.scss

我收到以下错误

Compilation Error
Error: File "c:\Users\Michael\www\demolaravel\resources\assets\sass\node_modules\bootstrap-sass\assets\stylesheets\bootstrap" not found
on line 9 of sass/c:\Users\Michael\www\demolaravel\resources\assets\sass\app.scss
>> @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

为什么他抱怨那个目录 - app.css(至少这个特定的行)也是原创的。这是 composer 安装它的方式。

// Fonts
@import url("https://fonts.googleapis.com/css?family=Raleway:300,400,600");

// Variables
@import "variables";

// Bootstrap
@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

body{
    padding-top: 80px;
}

我只是在最后添加了正文选择器 我使用 Visual Studio 代码和实时 sass 编译器扩展。但我也试过 Scout-App 还尝试放置绝对路径,但没有任何效果:(

【问题讨论】:

  • 您是否在项目中使用npm install 安装了依赖项?
  • 不,我忘了。将此作为答案,我接受

标签: laravel sass


【解决方案1】:

您似乎没有安装所有节点依赖项。

在您的项目上运行此命令npm install

@import 这样写

@import "../../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; 

npm run dev编译新的css

【讨论】:

  • 对不起,我做了 npm install 并且它安装了很多文件,但是如果我现在更改我的 scss 并让它编译,我会得到相同的消息。 :(
  • 是的“node_modules\bootstrap-sass”存在
  • 看来 elixir 正在尝试从 sass 文件夹中查找文件并附加路径,因此请尝试此路径,因为从 sass 目录 node_modules 向后退了 3 步。 @import "../../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
  • 不幸的是不是相同的消息:(
  • 你用的是哪个版本的 laravel?
【解决方案2】:

首先确保您已全局安装nodenpm。然后从你的项目中删除node_modules 目录,然后运行

npm rebuild node-sass

此命令可能需要一些时间才能执行。之后转到您的项目目录并运行npm install。然后使用laravel-mix 编译您的资产。

我在 linux 环境中也遇到了同样的问题,我遇到了这个解决方案。

【讨论】:

  • 您现在也可以使用 Visual Studio Code 的实时 sass 编译器扩展。但前提是我在@import 中跳三个目录,比如@import "../../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap";,谢谢
猜你喜欢
  • 2021-03-13
  • 1970-01-01
  • 2021-10-07
  • 2018-04-06
  • 2021-06-14
  • 2021-01-29
  • 2018-11-06
  • 1970-01-01
  • 2013-02-01
相关资源
最近更新 更多