假设我们在存储库中generate-mygenerator
。因此,我们generator.js
在根目录中有一个文件。
如果我想跑步gen gh-repo
怎么办?
我收到以下错误:
Error: Cannot find module 'lazy-cache'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/remi/d/dev/generate-package/utils.js:3:13)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
/home/remi/d/dev/generate/bin/generate.js:78
if (err) return app.emit('error', err);
^
TypeError: Cannot read property 'emit' of undefined
at /home/remi/d/dev/generate/bin/generate.js:78:23
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/base-runner/index.js:122:7)
at Liftoff.execute (/home/remi/d/dev/generate/node_modules/liftoff/index.js:203:12)
at module.exports (/home/remi/d/dev/generate/node_modules/flagged-respawn/index.js:51:3)
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/liftoff/index.js:195:5)
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/liftoff/index.js:170:7)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:686:11)
at startup (bootstrap_node.js:187:16)
生成器完成后我是否要重命名generator.js
然后重命名?generator.js.wait
重现错误的步骤:
存储库中的示例generate-package
:
remi@poremil:~
$ cd d/dev/generate-package/
remi@poremil:~/d/dev/generate-package:master
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
remi@poremil:~/d/dev/generate-package:master
$ node -v
v8.9.4
remi@poremil:~/d/dev/generate-package:master
$ npm -v
5.6.0
remi@poremil:~/d/dev/generate-package:master
$ ls
docs generator.js index.js LICENSE package.json README.md templates test utils.js
运行generate-gh-repo
:
remi@poremil:~/d/dev/generate-package:master
$ gen gh-repo
[23:33:06] starting generate
[23:33:06] using generator ~/d/dev/generate-package/generator.js
Error: Cannot find module 'lazy-cache'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/remi/d/dev/generate-package/utils.js:3:13)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
/home/remi/d/dev/generate/bin/generate.js:78
if (err) return app.emit('error', err);
^
TypeError: Cannot read property 'emit' of undefined
at /home/remi/d/dev/generate/bin/generate.js:78:23
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/base-runner/index.js:122:7)
at Liftoff.execute (/home/remi/d/dev/generate/node_modules/liftoff/index.js:203:12)
at module.exports (/home/remi/d/dev/generate/node_modules/flagged-respawn/index.js:51:3)
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/liftoff/index.js:195:5)
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/liftoff/index.js:170:7)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:686:11)
at startup (bootstrap_node.js:187:16)
或相同的运行generate-git
:
remi@poremil:~/d/dev/generate-package:master
$ gen git
[23:33:16] starting generate
[23:33:16] using generator ~/d/dev/generate-package/generator.js
Error: Cannot find module 'lazy-cache'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/remi/d/dev/generate-package/utils.js:3:13)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
/home/remi/d/dev/generate/bin/generate.js:78
if (err) return app.emit('error', err);
^
TypeError: Cannot read property 'emit' of undefined
at /home/remi/d/dev/generate/bin/generate.js:78:23
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/base-runner/index.js:122:7)
at Liftoff.execute (/home/remi/d/dev/generate/node_modules/liftoff/index.js:203:12)
at module.exports (/home/remi/d/dev/generate/node_modules/flagged-respawn/index.js:51:3)
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/liftoff/index.js:195:5)
at Liftoff.<anonymous> (/home/remi/d/dev/generate/node_modules/liftoff/index.js:170:7)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:686:11)
at startup (bootstrap_node.js:187:16)