node.js 编译时找不到 node-sass 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39330727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:33:01  来源:igfitidea点击:

node-sass command not found when compiling

node.jsmacossass

提问by Jameson

I have a problem with SASS for node.js on Mac (OS X El Capitan)

我在 Mac (OS X El Capitan) 上对 node.js 的 SASS 有问题

When i trying compile a scss file to css using command 'node-sass -o css sass/style.scss' I get the following error:

当我尝试使用命令 'node-sass -o css sass/style.scss' 将 scss 文件编译为 css 时,出现以下错误:

node-sass: command not found

node-sass:找不到命令

What's the problem and how i can solve it?

有什么问题,我该如何解决?

Thanks in advance!

提前致谢!

回答by CDT

It means command node-sassis missing in your system. node-sassis a node.js command which can be installed with

这意味着node-sass您的系统中缺少命令。 node-sass是一个可以安装的 node.js 命令

npm install -g node-sass

The -gswitch means a node.js command which can run globally is being installed. Without -gmeans a node.js library is being installed at current directory.

-g开关指的node.js命令,其可以在全局运行正在安装。没有-g意味着 node.js 库正在安装在当前目录中。

回答by S. Buda

In my case, I was getting errors like this because npm installdidn't run correctly. removing my node_modules and then rerunning that command removed my build errors.

就我而言,我收到这样的错误,因为npm install没有正确运行。删除我的 node_modules 然后重新运行该命令删除了我的构建错误。

回答by hustnzj

try this: npx node-sass -o css sass/style.scss

尝试这个: npx node-sass -o css sass/style.scss

npxwill check whether <command>exists in $PATH, or in the local project binaries, and execute it. The more detail explanation is here

npx将检查是否<command>存在于$PATH,或在本地项目二进制文件中,并执行它。更详细的解释在这里

回答by vladanPro

This helped me:

这帮助了我:

sudo npm install --unsafe-perm -g node-sass

回答by Yair Abad

At the same folder where you have the package.json file, open terminal and type this:

在你有 package.json 文件的同一个文件夹中,打开终端并输入:

npm install node-sass

If after install this dependency still failling, remove node_modules and type:

如果安装此依赖项后仍然失败,请删除 node_modules 并键入:

npm install

npm install will rebuild your node_modules folder with package.json dependencies updated (Previously, you install node-sass in package.json with 'npm install node-sass' command).

npm install 将重建您的 node_modules 文件夹并更新 package.json 依赖项(以前,您使用“npm install node-sass”命令在 package.json 中安装 node-sass)。

回答by Leonardo Pineda

go to https://github.com/sass/node-sassdownload .zip or clone repo add el folder node-sass in node-modules and en file package-lock.json add this.

转到https://github.com/sass/node-sass下载 .zip 或克隆 repo 在 node-modules 中添加 el 文件夹 node-sass 和 en 文件 package-lock.json 添加它。

"node-sass": {
  "version": "4.7.2",
  "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.2.tgz",
  "integrity": "sha512-CaV+wLqZ7//Jdom5aUFCpGNoECd7BbNhjuwdsX/LkXBrHl8eb1Wjw4HvWqcFvhr5KuNgAk8i/myf/MQ1YYeroA==",
  "dev": true,
  "requires": {
    "async-foreach": "0.1.3",
    "chalk": "1.1.3",
    "cross-spawn": "3.0.1",
    "gaze": "1.1.2",
    "get-stdin": "4.0.1",
    "glob": "7.1.2",
    "in-publish": "2.0.0",
    "lodash.assign": "4.2.0",
    "lodash.clonedeep": "4.5.0",
    "lodash.mergewith": "4.6.1",
    "meow": "3.7.0",
    "mkdirp": "0.5.1",
    "nan": "2.8.0",
    "node-gyp": "3.6.2",
    "npmlog": "4.1.2",
    "request": "2.79.0",
    "sass-graph": "2.2.4",
    "stdout-stream": "1.4.0",
    "true-case-path": "1.0.2"
  },

ok now

现在可以

~$ npm install

回答by Afsina

You may try this:

你可以试试这个:

pwd

Checkout to your project directory, for eg:desktop

签出到您的项目目录,对于 eg:desktop

ls -la

Then see your project name and its position. Whether it's in root. If its in root,

然后查看您的项目名称及其位置。无论是在root中。如果它在根中,

sudo chown -R <change to your position from root><projectname>/
cd <projectname>
cd ../
rm -rf node_modules/
ls
npm i

回答by Rishu Srivastav

to use sass you must have node installed and than use the following command

要使用 sass,您必须安装节点,然后使用以下命令

sudo npm install -g node-sass

this is for linux users only, if you have not used "sudo" you will get the following error

这仅适用于 linux 用户,如果您没有使用“sudo”,您将收到以下错误

node-sass not found