Error: Cannot find Module '../utils/composeObjs' after installing generator-stencil globally

Error: Cannot find Module '../utils/composeObjs' after installing generator-stencil globally

我正在 https://github.com/AkashGutha/generator-stencil

为 stenciljs 写一个生成器

我在项目的根目录下有一个小的实用函数。它只是一个文件 utils/composeObjects.js 导出一个函数 composeObjs。我在生成器的所有子生成器中都使用了这个函数。我在这些地方使用它:

我正在使用 npm link 在本地测试我的生成器,然后当我在空文件夹中执行 yo stencil 时,生成器可以正常工作。

然而,当我 npm publish 它并尝试 运行 yo stencil 它抛出以下错误。

module.js:538
    throw err;
    ^

Error: Cannot find module '../utils/composeObjects'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/Akash/.npm-global/lib/node_modules/generator-stencil/app/index.js:5:21)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

搜索后我发现在全局安装包时 require 不能按预期工作。但是,我查看了 github 上的其他一些生成器,其中一些使用了某种 util 函数,并且在全局安装时它们工作正常。

我也怀疑这可能是因为主模块 运行ning 是主要的 yeoman,因为 yo stencil 告诉 yeoman cli 使用那个generator.

我需要摆脱这个错误,也希望 niec 能够深入了解导致这个模块错误的原因。

这是 github 问题:https://github.com/AkashGutha/generator-stencil/issues/1

听起来您的生成器可能正在从 npm 包中删除您的 util 文件。这可能是由 .npmignore 文件或 file/folder 未包含在您的 package.json files property.

中引起的