wechaty-puppet-mock would failed with Cannot read property 'version' on first run
suntong opened this issue · comments
The wechaty-puppet-mock
would failed with Cannot read property 'version' on first run.
Here is the detailed log:
$ WECHATY_PUPPET=wechaty-puppet-mock node examples/starter-bot.js
16:33:12 INFO Wechaty <wechaty-puppet-mock>(wechaty) start() v0.27.60 is starting...
16:33:12 INFO PuppetManager install(wechaty-puppet-mock@^0.15.5) please wait ...
npm: npm
npm: + wechaty-puppet-mock@0.15.10
added 19 packages from 21 contributors and audited 25 packages in 1.017s
npm: found 0 vulnerabilities
16:33:14 INFO PuppetManager install(wechaty-puppet-mock@^0.15.5) done
TypeError: Cannot read property 'version' of undefined
at Object.<anonymous> (/path/to/nodejs/node_modules/wechaty-puppet-mock/dist/src/config.js:23:23)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/path/to/nodejs/node_modules/wechaty-puppet-mock/dist/src/puppet-mock.js:35:18)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/path/to/nodejs/node_modules/wechaty-puppet-mock/dist/src/index.js:6:10)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at /path/to/nodejs/node_modules/wechaty/dist/src/puppet-manager.js:89:82
16:33:14 ERR Wechaty start() exception: Cannot read property 'version' of undefined
16:33:14 ERR StarterBot TypeError: Cannot read property 'version' of undefined
- When run the 2nd time, it will be fine.
- It will happen (again) when a new module is added into the
node_modules
directory, it seems.
Don't know if it is specific to wechaty-puppet-mock
or it is underlying wechaty
modules wechaty/dist/src/puppet-manager.js
though, as I can't test online.
PS. my env:
$ npm ls --depth=0
. . .
├── wechaty@0.27.60
├── wechaty-puppet@0.14.1
├── wechaty-puppet-mock@0.14.2
└── wechaty-puppet-puppeteer@0.16.1
$ node --version
v12.9.1
$ lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
I can not reproduce your result.
Mine is:
$ WECHATY_PUPPET=wechaty-puppet-mock node examples/starter-bot.js
08:46:26 INFO Wechaty <wechaty-puppet-mock>(wechaty) start() v0.27.53 is starting...
08:46:26 INFO StarterBot Cancel(0) - https://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Fnot-exist.com
08:46:26 INFO StarterBot Starter Bot Started.
08:46:26 INFO StarterBot Contact<mock-name> login
08:46:29 INFO StarterBot Message#Text[🗣Contact<mock-name>] mock text
08:46:32 INFO StarterBot Message#Text[🗣Contact<mock-name>] mock text
So I'd like to suggest that you can do a rm -fr node_modules && git pull && npm install
then try again.
- When run the 2nd time, it will be fine.
- It will/might happen (again) when a new module is added ...
So unless you are installing from fresh, (or maybe added a new module), you cannot reproduce it.
I've reproduced it many times like that, the most reliable way to reproduce is to have a brand new wechaty module installation.
Here is another log, from another brand new wechaty module installation:
$ WECHATY_PUPPET=wechaty-puppet-mock node examples/starter-bot.js
19:57:09 INFO PuppetManager install(wechaty-puppet-mock@^0.15.5) done
TypeError: Cannot read property 'version' of undefined
at Object.<anonymous> (/path/to/nodejs/wechaty-getting-started/node_modules/wechaty-puppet-mock/dist/src/config.js:23:23)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/path/to/nodejs/wechaty-getting-started/node_modules/wechaty-puppet-mock/dist/src/puppet-mock.js:35:18)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/path/to/nodejs/wechaty-getting-started/node_modules/wechaty-puppet-mock/dist/src/index.js:6:10)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at /path/to/nodejs/wechaty-getting-started/node_modules/wechaty/dist/src/puppet-manager.js:89:82
19:57:09 ERR Wechaty start() exception: Cannot read property 'version' of undefined
19:57:09 ERR StarterBot TypeError: Cannot read property 'version' of undefined
What do you mean "brand new"?
Please provide the details about which version you had installed, with your re-producible install scripts.
Ok, I guess I had catch it in wechaty package.json files.
I had specified the mock version in it before. Will remove it and publish a new version.
Should be fixed in Wechaty v0.28, please try the latest master branch.
Thanks for reporting this problem!
- I saw the fix was removing
wechaty-puppet-mock
entirely, but I think it might not work for all cases. I.e., thewechaty-puppet-mock
is not required and normally need to be installed manually, which means re-introducing thewechaty-puppet-mock
entry back to thepackage.json
. Hmm... maybe not. So... - how exactly to reproduce it? I got it again when trying the
examples/advanced/gist-bot/index.js
, but now everything is OK for me.
That's because this issue should have already been fixed.
Please let me know if you have any trouble from the latest master branch code, or Wechaty v0.28 or above.
I get the latest Wechaty v0.28 but am still seeing the problem:
$ WECHATY_PUPPET=wechaty-puppet-mock node examples/advanced/gist-bot/index.js
=============== Powered by Wechaty ===============
-------- https://github.com/Chatie/wechaty --------
Please wait... I'm trying to login in...
14:07:46 INFO Wechaty <wechaty-puppet-mock>() start() v0.28.3 is starting...
14:07:46 INFO PuppetManager install(wechaty-puppet-mock@^0.16.1) please wait ...
npm: + wechaty-puppet-mock@0.16.1
added 48 packages from 37 contributors and audited 94 packages in 2.959s
npm: found 0 vulnerabilities
14:07:50 INFO PuppetManager install(wechaty-puppet-mock@^0.16.1) done
TypeError: Cannot read property 'version' of undefined
at Object.<anonymous> (/path/to/nodejs/node_modules/wechaty-puppet-mock/dist/src/config.js:23:23)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/path/to/nodejs/node_modules/wechaty-puppet-mock/dist/src/puppet-mock.js:35:18)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/path/to/nodejs/node_modules/wechaty-puppet-mock/dist/src/index.js:6:10)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at /path/to/nodejs/wechaty-getting-started/node_modules/wechaty/dist/src/puppet-manager.js:89:82
14:07:50 ERR Wechaty start() exception: Cannot read property 'version' of undefined
14:07:50 INFO Bot error: TypeError: Cannot read property 'version' of undefined
14:07:50 INFO Wechaty <wechaty-puppet-mock> stop() v0.28.3 is stoping ...
14:07:50 WARN Wechaty stop() puppet.stop() exception: static puppet not found for Wechaty, please see issue #1217: https://github.com/Chatie/wechaty/issues/1217
And again, when run for the 2nd time, it is be fine.
Interesting. I'll look in to it later.