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

How to run hot-import-bot example #1222

Closed
suntong opened this issue May 22, 2018 · 5 comments
Closed

How to run hot-import-bot example #1222

suntong opened this issue May 22, 2018 · 5 comments
Labels

Comments

@suntong
Copy link
Contributor

suntong commented May 22, 2018

I was getting the following errors (enclosed in "Show Logs") when running the hot-import-bot examples. Running with node index.js will give me the same error as well. What could be wrong? All my tools are of the latest version now:

Wechaty is v0.14.4, and

$ node -v
v10.1.0

$ npm -v
6.0.1

$ ts-node -v
ts-node v6.0.3
node v10.1.0
typescript v2.8.3
cache "/tmp/ts-node-ebbe..ce010e"
Show Logs

Paste the full output logs here

# PASTE FULL LOG OUTPUT AT HERE:
cd Chatie/wechaty/examples/hot-import-bot

Chatie/wechaty/examples/hot-import-bot$ ts-node index.js 
23:57:46 INFO Wechaty v0.14.4 starting...
23:57:46 ERR HotImport importFile(/path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-friend.js) rejected: SyntaxError: Unexpected token export
23:57:46 ERR HotImport importFile(/path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-login.js) rejected: SyntaxError: Unexpected token export
23:57:46 ERR HotImport importFile(/path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-message.js) rejected: SyntaxError: Unexpected token export
23:57:46 ERR HotImport importFile(/path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-scan.js) rejected: SyntaxError: Unexpected token export
23:57:46 ERR Wechaty onModulePath(friend, ./listeners/on-friend) hotImport() exception: SyntaxError: Unexpected token export
23:57:46 ERR Wechaty onModulePath(login, ./listeners/on-login) hotImport() exception: SyntaxError: Unexpected token export
23:57:46 ERR Wechaty onModulePath(message, ./listeners/on-message) hotImport() exception: SyntaxError: Unexpected token export
23:57:46 ERR Wechaty onModulePath(scan, ./listeners/on-scan) hotImport() exception: SyntaxError: Unexpected token export
(node:25428) UnhandledPromiseRejectionWarning: /path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-friend.js:19
export default async function onFriend (contact, request) {
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:646:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Promise.resolve.then (/path/to/node_modules/hot-import/src/hot-import.ts:273:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
    at Object.<anonymous> (/usr/lib/node_modules/ts-node/src/bin.ts:145:12)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
(node:25428) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:25428) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:25428) UnhandledPromiseRejectionWarning: /path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-login.js:19
export default async function onLogin (user) {
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:646:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Promise.resolve.then (/path/to/node_modules/hot-import/src/hot-import.ts:273:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
    at Object.<anonymous> (/usr/lib/node_modules/ts-node/src/bin.ts:145:12)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
(node:25428) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
(node:25428) UnhandledPromiseRejectionWarning: /path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-message.js:19
export default async function onMessage (message) {
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:646:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Promise.resolve.then (/path/to/node_modules/hot-import/src/hot-import.ts:273:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
    at Object.<anonymous> (/usr/lib/node_modules/ts-node/src/bin.ts:145:12)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
(node:25428) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 7)
(node:25428) UnhandledPromiseRejectionWarning: /path/to/Chatie/wechaty/examples/hot-import-bot/listeners/on-scan.js:19
export default async function onScan (url, code) {
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:646:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Promise.resolve.then (/path/to/node_modules/hot-import/src/hot-import.ts:273:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
    at Object.<anonymous> (/usr/lib/node_modules/ts-node/src/bin.ts:145:12)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
@suntong suntong changed the title How to run hot-import-bot examples How to run hot-import-bot example May 22, 2018
@huan
Copy link
Member

huan commented May 23, 2018

Will have a look into this after I finish the v0.15

@suntong
Copy link
Contributor Author

suntong commented May 23, 2018

Alright then. thx.

@huan
Copy link
Member

huan commented May 27, 2018

I had just tested it with the following commands, it works without any problem:

┌ zixia@zixia-desktop:~/chatie/wechaty/examples/hot-import-bot [16:16:17] tty:[0] jobs:[0]
└ {master} $ pwd
/home/zixia/chatie/wechaty/examples/hot-import-bot
┌ zixia@zixia-desktop:~/chatie/wechaty/examples/hot-import-bot [16:16:22] tty:[0] jobs:[0]
└ {master} $ ll
total 16
-rw-r--r-- 1 zixia 1400 Mar 12 21:58 index.js
drwxr-xr-x 2 zixia 4096 Mar 12 21:58 listeners/
-rw-r--r-- 1 zixia  744 Feb 26 12:39 README.md
-rwxr-xr-x 1 zixia  164 May 27 16:15 run-hot-import-bot.sh*
┌ zixia@zixia-desktop:~/chatie/wechaty/examples/hot-import-bot [16:16:22] tty:[0] jobs:[0]
└ {master} $ cat run-hot-import-bot.sh 
#!/usr/bin/env bash
set -e

docker run -t -i --rm --name wechaty -e WECHATY_LOG="$WECHATY_LOG" --mount type=bind,source="$(pwd)",target=/bot zixia/wechaty index.js
┌ zixia@zixia-desktop:~/chatie/wechaty/examples/hot-import-bot [16:16:40] tty:[0] jobs:[0]
└ {master} $ WECHATY_LOG=verbose ./run-hot-import-bot.sh 

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  ____                            _   _             
 / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _ 
| |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` |
| |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| |
 \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |
                                              |___/ 
  ____ _           _   ____        _       
 / ___| |__   __ _| |_| __ )  ___ | |_ ___ 
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/
                                           

Starting Wechaty v0.13.70 with Node.js v9.5.0 ...
Working directory: /bot
Executing babel-node --presets env index.js
08:16:45 INFO Config registering process.on("unhandledRejection") for development/debug
08:16:45 VERB Config constructor()
08:16:47 VERB Wechaty contructor()
08:16:47 VERB Profile constructor(null)
08:16:47 VERB Wechaty on(friend, ./listeners/on-friend) registered
08:16:47 VERB Wechaty onModulePath() hotImpor(/bot/listeners/on-friend)
08:16:47 VERB Wechaty on(login, ./listeners/on-login) registered
08:16:47 VERB Wechaty onModulePath() hotImpor(/bot/listeners/on-login)
08:16:47 VERB Wechaty on(message, ./listeners/on-message) registered
08:16:47 VERB Wechaty onModulePath() hotImpor(/bot/listeners/on-message)
08:16:47 VERB Wechaty on(scan, ./listeners/on-scan) registered
08:16:47 VERB Wechaty onModulePath() hotImpor(/bot/listeners/on-scan)
08:16:47 INFO Wechaty v0.13.70 starting...
08:16:47 VERB Wechaty puppet: web
08:16:47 VERB Wechaty profile: undefined
08:16:47 VERB Wechaty uuid: 6a6756b9-3260-4b25-99f0-f9e0d2af733c
08:16:47 VERB StateSwitch <Wechaty> on(pending) <- (false)
08:16:47 VERB Profile load() file: null
08:16:47 VERB Profile load() no file, NOOP
08:16:47 VERB Wechaty initPuppet()
08:16:47 VERB Wechaty initPuppet() puppet.on(error) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(friend) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(heartbeat) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(login) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(logout) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(message) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(room-join) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(room-leave) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(room-topic) registered
08:16:47 VERB Wechaty initPuppet() puppet.on(scan) registered
08:16:47 VERB Config puppetInstance(PuppetWeb)
08:16:47 VERB PuppetWeb init() with Profile<null>
08:16:47 VERB StateSwitch <Puppet> on(pending) <- (false)
08:16:47 VERB PuppetWeb initWatchdogForPuppet()
08:16:47 VERB PuppetWeb initWatchdogForScan()
08:16:47 VERB PuppetWeb initBridge()
08:16:47 VERB PuppetWebBridge constructor()
08:16:47 VERB PuppetWebBridge init()
08:16:47 VERB StateSwitch <PuppetWebBridge> on(pending) <- (false)
08:16:47 VERB PuppetWebBridge initBrowser()
08:16:47 VERB PUppetWebBridge initBrowser() version: HeadlessChrome/65.0.3312.0
08:16:47 VERB PuppetWebBridge init() initBrowser() done
08:16:47 VERB PuppetWebBridge initPage()
08:16:47 VERB Profile get(cookies)
08:16:47 VERB PuppetWebBridge cookieDomain(undefined)
08:16:47 VERB PuppetWebBridge initPage() before page.goto(url)
08:16:48 VERB PuppetWebBridge initPage() after page.goto(url)
08:16:48 VERB PuppetWebBridge initPage() on(load) https://wx.qq.com/
08:16:48 VERB PuppetWebBridge readyAngular()
08:16:48 VERB PuppetWebBridge inject()
08:16:48 VERB PuppetWebBridge ding(ding() OK!)
08:16:48 VERB PuppetWebBridge clickSwitchAccount()
08:16:48 VERB PuppetWebBridge clickSwitchAccount() listXpath()
08:16:48 VERB StateSwitch <PuppetWebBridge> on(true) <- (pending)
08:16:48 VERB PuppetWebBridge init() initPage() done
08:16:48 VERB PuppetWeb initBridge() done
08:16:48 VERB StateSwitch <Puppet> on(true) <- (pending)
08:16:48 VERB PuppetWeb init() done
08:16:48 VERB Wechaty on(heartbeat, function) registered
08:16:48 VERB Wechaty onFunction(heartbeat)
08:16:48 VERB StateSwitch <Wechaty> on(true) <- (pending)
08:16:49 VERB PuppetWebEvent onScan({code: 0, url: https://login.weixin.qq.com/qrcode/QelXt2S5Ig==})
08:16:49 VERB Profile set(cookies, [object Object],[object Object],[object Object])
08:16:49 VERB Profile save() file: null
08:16:49 VERB Profile save() no file, NOOP
08:16:49 VERB Wechaty init() throttleQueue.subscribe() new item: [object Object]
0 'https://login.weixin.qq.com/qrcode/QelXt2S5Ig=='
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █▄▀ ▀ █ ██▀█▄▄█ ▄▄▄▄▄ █
█ █   █ █   █▀▄▀▄ ▀ ▄▀█ █   █ █
█ █▄▄▄█ █▄█▀ ▄ █▄▄▀▀ ██ █▄▄▄█ █
█▄▄▄▄▄▄▄█▄█ █ █ ▀ ▀▄▀▄█▄▄▄▄▄▄▄█
█▄ ▄▄▀▀▄▀▄█ ▄ ▄▄▄ ▄ ▀█ ▀▀ ▄▄█ █
█▄  ▄▀█▄ ▀  ▄▄ ██▀█▀█ ▄▄█▀█▄▄▀█
█▀█▄▀▀▀▄▀▄ ▄▀ █▄█ ▄█ █▄▀██▄ ▀▀█
█▀▀ ▄█ ▄▄▀   █▄▀▀█▄▄▄▄ ▀  █▄ ▄█
██▀ ██▄▄█ ▄▀█▄▄ █▄▀▄▄  █ ▄ ▀ ██
█▄█▀▄▀█▄█▀▀▀▀██▄▄▀▀▀█▀▀▀▄▀█ ███
██▄▄▄▄█▄▄ ▀▀██▀▀█  ▀▀ ▄▄▄   ▀▀█
█ ▄▄▄▄▄ ██▀▀▀▀▀▀█ █ ▄ █▄█  █▄██
█ █   █ █▀▀▀ █▀▀▄▀▄█▀  ▄  ▀▄▄ █
█ █▄▄▄█ █ █▄█ ▀▄█▀█ ▄ ██▄▀▀▄▀▄█
█▄▄▄▄▄▄▄█▄▄█▄███▄███▄▄▄██▄██▄██

08:16:49 VERB Profile set(cookies, [object Object],[object Object],[object Object])
08:16:49 VERB Profile save() file: null
08:16:49 VERB Profile save() no file, NOOP
^C Script terminated by Control-C 
   ____ _        _            ____  
  / ___| |_ _ __| |    _     / ___| 
 | |   | __| '__| |  _| |_  | |     
 | |___| |_| |  | | |_   _| | |___  
  \____|\__|_|  |_|   |_|    \____| 
                                    

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  _____      _ _     _ _____  ___   
 | ____|_  _(_) |_  / |___ / / _ \  
 |  _| \ \/ / | __| | | |_ \| | | | 
 | |___ >  <| | |_  | |___) | |_| | 
 |_____/_/\_\_|\__| |_|____/ \___/  
                                    

@huan huan added the question label May 27, 2018
@suntong
Copy link
Contributor Author

suntong commented May 27, 2018

Thanks @zixia, so it can run within docker just fine.

How can I make it run under normal command line as well, not within docker but just plain Linux shell? Thx.

@huan
Copy link
Member

huan commented Jul 16, 2018

Confirmed that the example cannot be run outside docker.

Merge to wechaty/getting-started#37

@huan huan closed this as completed Jul 16, 2018
@huan huan added bug and removed question labels Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants