您不知道已安装发电机

2024-01-08

我刚刚安装了 Yeoman 和一些发电机。然而,由于/usr/lib文件夹受到保护,我选择更改 NPM 安装其软件包的位置的前缀。

现在,一切都在安装~/.node。我也改变了我的$PATH并添加了~/.node/bin。但是,当我执行yo <name of generator>,我得到以下信息:

Error node 

You don't seem to have a generator with the name node installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 0 registered generators run yo with the `--help` option.

正如您可以在此处阅读的那样,它告诉我有 0 个已注册的生成器,但我正确安装了它们(并且完成时没有错误)。例如,我可以找到已安装的发电机~/.node/lib/node_modules/generator-node存在并且当我执行以下命令时:

npm list -g

我可以找到我安装的生成器(所以我认为这不是 npm 的问题)。

所以我认为 Yeoman(或者更准确地说 Yo)不知道生成器安装在自定义文件夹中,但我还没有找到任何方法来配置它。


除了将其添加到您的路径之外,您还应该设置NODE_PATH环境变量。这自耕农/生成器代码 https://github.com/yeoman/generator/blob/34441c20f86c0201b29d0ba1ff05a58baedcd654/lib/env/index.js#L100-106首先会看那里:

// We tried using NPM to get the global modules path, but it haven't work out
// because of bugs in the parseable implementation of `ls` command and mostly
// performance issues. So, we go with our best bet for now.
if (process.env.NODE_PATH) {
  _.compact(process.env.NODE_PATH.split(/[;:]/g)).forEach(this.appendPath, this);
  return;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

您不知道已安装发电机 的相关文章

随机推荐