【问题标题】:Node / npm : File to import not found when compiling scss with node-sassNode / npm:使用node-sass编译scss时找不到要导入的文件
【发布时间】:2016-07-09 16:39:01
【问题描述】:

我正在尝试使用package.json 中的以下脚本将sassnode-sass 一起编译:

"node-sass": "node-sass --output-style compressed 'src/scss/styles.scss' 'dist/css/bundle.min.css'",

我的styles.scss

@import "bourbon";
@import "neat";

body {background: red;}

但是当我运行npm run node-sass 时,我收到以下错误:

  "formatted": "Error: File to import not found or unreadable: bourbon\n       Parent style sheet: /Users/deangibson/Desktop/personal_site/src/scss/styles.scss\n        on line 1 of src/scss/styles.scss\n>> @import \"bourbon\";\n   ^\n",
  "message": "File to import not found or unreadable: bourbon\nParent style sheet: /Users/deangibson/Desktop/personal_site/src/scss/styles.scss",
  "column": 1,
  "line": 1,
  "file": "/Users/deangibson/Desktop/personal_site/src/scss/styles.scss",
  "status": 1
}

我的项目结构如下:

当涉及到依赖关系时,节点不应该自动签入 node_modules 吗?我不明白我在这里做错了什么......

【问题讨论】:

    标签: javascript node.js sass npm node-sass


    【解决方案1】:

    是的,node 会自动在来自 node_modules 的 JavaScript 文件中查找您 require 的内容。但是,您正在执行一个命令行应用程序node-sass,但它并没有这样做。

    您可以像这样将--include-path 提供给node-sass 命令行应用程序(多行以便于阅读,需要在package.json 中为单行)

    node-sass 
      --output-style compressed 
      --include-path node_modules/bourbon/app/assets/stylesheets/ 
      --include-path node_modules/bourbon-neat/app/assets/stylesheets/ 
      'src/scss/styles.scss' 
      'dist/css/bundle.min.css'
    

    如果你写了render JavaScript file that is executed with node,你可以通过合并arrays exported by the bourbon modules when you require them来设置includePath

    【讨论】:

      猜你喜欢
      • 2016-05-11
      • 2018-10-11
      • 2019-01-27
      • 2017-01-12
      • 2013-03-18
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 2018-05-05
      相关资源
      最近更新 更多