【问题标题】:Cannot npn run sass不能 npm 运行 sass
【发布时间】:2021-05-04 23:05:17
【问题描述】:

我在文件夹 C:\Users\borka\Desktop\Courses\HTML & CSS (Traversy)\Sandbox\13_sass 中,使用 VSCode 中的 bash 终端和 npm 版本 6.14.8

我已成功运行npm init -ynpm install node-sass,然后编辑package.json 文件以包含"scripts": { "sass": "node-sass -w scss/ -o dist/css/ --recursive" }

然后,我创建了一个scss 目录,其中包含main.scss,以及一个dist 目录。最后,我运行了npm run sass,但它失败了,这就是我得到的结果:

> 13_sass@1.0.0 sass C:\Users\borka\Desktop\Courses\HTML & CSS (Traversy)\Sandbox\13_sass
> node-sass -w scss/ -o dist/css/ --recursive

'CSS' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'C:\Users\borka\Desktop\Courses\node-sass\bin\node-sass'    
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)       
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 13_sass@1.0.0 sass: `node-sass -w scss/ -o dist/css/ --recursive`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the 13_sass@1.0.0 sass script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\borka\AppData\Roaming\npm-cache\_logs\2021-01-31T16_01_42_707Z-debug.log

注意 Error: Cannot find module 行如何显示完全错误的路径,甚至根本不存在。

我以前从未使用过 sass,也不知道问题出在哪里。

【问题讨论】:

    标签: css node.js npm sass


    【解决方案1】:

    我还不能发表评论,但我认为您正在寻找将您的 SASS 编译为 CSS 的包是 this one。我注意到您使用node-sass 而不是常规的sass。你可以通过运行来安装它:

    npm install -g sass
    

    在您的系统上全局安装它,然后编译您的 SASS。

    试试我分享的那个,或者,如果你使用的是像 VSCode 这样的 IDE,你可以下载一个像 Live Sass Compiler 这样的扩展(这是我通常使用的)。

    【讨论】:

      【解决方案2】:

      显然路径中的 & 号是原因。我从文件夹名称“HTML & CSS”中删除了它,现在一切正常。

      【讨论】:

        猜你喜欢
        • 2021-07-31
        • 1970-01-01
        • 2021-11-17
        • 1970-01-01
        • 2018-11-28
        • 2021-10-05
        • 1970-01-01
        • 2020-06-09
        相关资源
        最近更新 更多