在 Windows 上安装 Node.js 和 Grunt

标签 node.js gruntjs

我安装了 Node.js 并运行了 npm install -g grunt-cli 我将 cd 转到了我要处理的应用程序的目录并遵循说明 here .当我在我的 cmd 中运行 grunt 时,它返回

module.js:340
    throw err;
          ^

Error: Cannot find module '\\Server\username$\Redirected\AppData\npm\AppData\npm\node_modules\grunt-cli'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

我真的不确定为什么它会尝试从 \AppData\npm\AppData\npm\ 读取,因为我没有做任何更改而且我不知道如何更改 grunt 位置

但是当我使用 npm install -g grunt-cli 时,它会下载并安装到以下 \\Server\username$\Redirected\AppData\npm\node_modules\grunt-cli

最佳答案

您需要更改全局安装目录。

试试这个..

在 C:\Users{用户名}\中,创建包含以下内容的 .npmrc 文件:

prefix = "C:\\Users\\{username}\\AppData\\Roaming\\npm"

此处对此进行了更全面的讨论:

Change default global installation directory for node.js modules in Windows?

关于在 Windows 上安装 Node.js 和 Grunt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135929/

相关文章:

javascript - 工厂尝试创建两个具有相同属性的对象

javascript - ReactJS 中的录音

javascript - Grunt.js DEV 与 PROD 任务

javascript - 如何使用 grunt autoprefixer 定位 IE9 及更高版本?

javascript - 创建调用远程 REST API 并返回结果的 Node REST API

javascript - Chai - 测试对象数组中的 bool 值

node.js - 将 PGP 加密的二进制文件编码为 NodeJS 的 Base64

javascript - 从另一个 gruntfile 加载 grunt 任务

javascript - grunt-include-source 多个配置

node.js - Grunt 产生的进程没有捕获输出