Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wechaty-puppet-mock would failed with Cannot read property 'version' on first run #31

Open
suntong opened this issue Sep 1, 2019 · 10 comments
Labels
bug Something isn't working

Comments

@suntong
Copy link

suntong commented Sep 1, 2019

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: + [email protected]
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 
. . . 
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

$ node --version
v12.9.1

$ lsb_release -a 
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic
@huan
Copy link
Member

huan commented Sep 2, 2019

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.

@suntong
Copy link
Author

suntong commented Sep 2, 2019

  • 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.

@suntong
Copy link
Author

suntong commented Sep 2, 2019

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

@huan
Copy link
Member

huan commented Sep 2, 2019

What do you mean "brand new"?

Please provide the details about which version you had installed, with your re-producible install scripts.

@huan
Copy link
Member

huan commented Sep 2, 2019

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.

huan added a commit to wechaty/wechaty that referenced this issue Sep 2, 2019
@huan
Copy link
Member

huan commented Sep 2, 2019

Should be fixed in Wechaty v0.28, please try the latest master branch.

Thanks for reporting this problem!

@huan huan added the bug Something isn't working label Sep 2, 2019
@suntong
Copy link
Author

suntong commented Sep 2, 2019

  • I saw the fix was removing wechaty-puppet-mock entirely, but I think it might not work for all cases. I.e., the wechaty-puppet-mock is not required and normally need to be installed manually, which means re-introducing the wechaty-puppet-mock entry back to the package.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.

@huan
Copy link
Member

huan commented Sep 2, 2019

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.

@suntong
Copy link
Author

suntong commented Sep 2, 2019

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:/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: + [email protected]
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:/Chatie/wechaty/issues/1217

And again, when run for the 2nd time, it is be fine.

@huan
Copy link
Member

huan commented Sep 2, 2019

Interesting. I'll look in to it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants