node.js 命令行无法识别节点sass

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42518621/
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 18:03:07  来源:igfitidea点击:

Node-sass is not recognized by command line

node.jsnpmcommand-line-toolnode-sass

提问by Sam Woolerton

I'm trying to set up node-sass, following the instructions on CSS-Tricks. Node and npm are installed correctly, and the node-sass installation worked too. When I go to run node-sass --output-style compressed -o dist/css src/scss, though, I get an error message stating

我正在尝试按照 CSS-Tricks 上说明设置 node-sass 。Node 和 npm 安装正确,node-sass 安装也工作正常。node-sass --output-style compressed -o dist/css src/scss但是,当我开始运行时,我收到一条错误消息,指出

'node-sass' is not recognized as an internal or external command, operable program or batch file.

'node-sass' 不是内部或外部命令,也不是可运行的程序或批处理文件。

I've done a fair bit of Googling and searched Stack Overflow directly. My question isn't about "node" not being recognised as a command. I know node is working as I can run node -vand npm -v, and node-sass was successfully installed after running npm install --save-dev node-sass(there's a folder in node_modules) and no errors appeared in the command line.

我已经做了一些谷歌搜索并直接搜索了Stack Overflow。我的问题不是关于“节点”不被识别为命令。我知道节点工作,我可以运行node -v,并npm -v和节点青菜运行后,安装成功npm install --save-dev node-sass(有一个在node_modules一个文件夹),并没有出现在命令行中的错误。

Other information: I am running Windows 10 and just did a clean install of node and npm before trying to use node-sass.

其他信息:我正在运行 Windows 10,在尝试使用 node-sass 之前,我刚刚全新安装了 node 和 npm。

EDIT: I uninstalled and reinstalled with -g thanks to @Bhavik's suggestion, and it's now working

编辑:由于@Bhavik 的建议,我使用 -g 卸载并重新安装,现在可以使用了

回答by Bhavik

You need to install it globally

你需要全局安装

npm install -g node-sass

Or add it in package.json

或者添加进去 package.json

"devDependencies": {
    "node-sass": "4.5.0"
},
"scripts" : {
    "node-sass": "node-sass --output-style compressed -o dist/css src/scss"
}

And then do
1. npm i, which in this case would be similar to npm install --save-dev node-sass
2. npm run node-sass

然后执行
1. npm i,在这种情况下类似于npm install --save-dev node-sass
2。npm run node-sass

Reference: npm scripts, npm-run-scripts

参考:npm scriptsnpm-run-scripts

回答by Onat Korucu

npm commands check "node_package" folder and try to run things there. You can try

npm 命令检查“node_package”文件夹并尝试在那里运行。你可以试试

npx run scss 

to install scss and then run it, even if it is not installed before.

安装scss然后运行它,即使它之前没有安装。

回答by Gabi Wissotzky

The below solves the problem

下面解决问题

yarn global add node-sass-chokidar

回答by Aathil Ahamed

This is a simple problem don't worry too much. Just go to package.jsonfile and add this code

这是一个简单的问题,不要太担心。只需转到package.json文件并添加此代码

"devDependencies": {
    "node-sass": "4.9.2"
},
"scripts" : {
    "node-sass": "node-sass --output-style compressed -o dist/css/ scss --recursive"
}

and just save the file.

并保存文件。

And run this command,

并运行此命令,

**npm run node-sass**

That's all

就这样

回答by Isaac Pak

node-sass v4.13+

node-sass v4.13+

  1. Install node-sass in your project locally
  1. 在您的项目中本地安装 node-sass
cd <root path of your project>
yarn add -D node-sass
// or
npm install -D node-sass
  1. Add a script to your package.json
  1. 将脚本添加到 package.json
"scripts" : {
...
  "compile:sass": "node-sass --recursive --watch <sass directory> --output <css directory>",
...
}
  1. Run the script from the command line
  1. 从命令行运行脚本
yarn compile:sass
// or
npm run compile:sass