【问题标题】:node-sass does not compile scss file using npm run css commandnode-sass 不使用 npm run css 命令编译 scss 文件
【发布时间】:2016-05-11 02:42:13
【问题描述】:

我使用npm 作为构建工具。我的package.json 文件中有以下行。

"scripts": {
    "css": "node-sass --include ./node_module --include-scss --compress ./src/css/main.scss ./dist/css/style.css",
}

当我运行npm run css 时,它会在终端的输出下方显示

> website@1.0.0 css /Projects/Lab/website
> node-sass --include ./node_module --include-scss --compress ./src/css/main.scss ./dist/css/style.css

但是当我检查./dist/css/style.css文件时,它是空的。

为什么以及如何解决这个问题?

更新

现在我遇到了错误

/Projects/website/node_modules/node-sass/lib/extensions.js:158
    throw new Error([
    ^

Error: The `libsass` binding was not found in /Projects/website/node_modules/node-sass/vendor/darwin-x64-47/binding.node
This usually happens because your node version has changed.
Run `npm rebuild node-sass` to build the binding for your current node version.
    at Object.sass.getBinaryPath (/Projects/website/node_modules/node-sass/lib/extensions.js:158:11)
    at Object.<anonymous> (/Projects/website/node_modules/node-sass/lib/index.js:16:36)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Projects/website/node_modules/node-sass/lib/render.js:9:12)
    at Module._compile (module.js:413:34)

npm ERR! Darwin 13.4.0
npm ERR! argv "/Users/xafar/.nvm/versions/node/v5.5.0/bin/node" "/Users/xafar/.nvm/versions/node/v5.5.0/bin/npm" "run" "css"
npm ERR! node v5.5.0
npm ERR! npm  v3.3.12
npm ERR! code ELIFECYCLE
npm ERR! website@1.0.0 css: `node-sass --include-scss ./src/css/main.scss ./dist/css/style.css`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the website@1.0.0 css script 'node-sass --include-scss ./src/css/main.scss ./dist/css/style.css'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the website package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-sass --include-scss ./src/css/main.scss ./dist/css/style.css
npm ERR! You can get their info via:
npm ERR!     npm owner ls website
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Projects/website/npm-debug.log
[nodemon] app crashed - waiting for file changes before starting...

在我的package.json 文件中更改以下行之后。

"css": "node-sass --include-scss ./src/css/main.scss ./dist/css/style.css", // see above for original line.

我正在关注以下博客以使其正常工作。

https://moroccojs.org/tutorials/npm-based-front-end-workflow/ https://medium.com/@brianhan/watch-compile-your-sass-with-npm-9ba2b878415b#.pfupo150c

【问题讨论】:

    标签: javascript node.js build sass npm


    【解决方案1】:

    2021 年,node-sass 正式弃用,建议改用 dart sass。

    sass 语法改变了,只有新的 dart-sass 支持它。

    sass-lang.com/blog/libsass-is-depr...

    如何迁移? 如果你是 Node Sass 的用户,迁移到 Dart Sass 很简单:只需将 package.json 文件中的 node-sass 替换为 sass。这两个包都公开了相同的 JavaScript API。

    【讨论】:

      【解决方案2】:

      您的编码文件中可能存在错误。
      例如,我有一个 main.scss 文件,其中导入了多个文件。
      我的问题通过 main.scss 文件中的几个导入评论得到解决:

      另外,您可以重新安装node_module 并清除节点缓存。

      【讨论】:

        猜你喜欢
        • 2016-07-09
        • 2021-06-30
        • 1970-01-01
        • 1970-01-01
        • 2018-10-11
        • 2015-10-05
        • 2021-08-15
        • 1970-01-01
        • 2017-01-12
        相关资源
        最近更新 更多