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

Error: Cannot find module 'babel-plugin-transform-runtime' from '/bot' #1536

Closed
csea007 opened this issue Aug 10, 2018 · 7 comments
Closed

Comments

@csea007
Copy link

csea007 commented Aug 10, 2018

Provide Your Network Information

  1. Beijing,China
  2. Macbook

Run npm run doctor or wechaty run doctor(for docker user), paste output here

**when running "docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty tuling.js'

report the following error, who can help me? thanks in advance**

_WECHATY Environment Variables: 1
WECHATY_DOCKER=1

Starting Docker Container for Wechaty v0.19.123 with Node.js v10.8.0 ...
Working directory: /bot
Executing babel-node --presets @babel/env tuling.js
/wechaty/node_modules/@babel/core/lib/config/files/plugins.js:152
    throw e;
    ^

Error: Cannot find module 'babel-plugin-transform-runtime' from '/bot'
    at Function.module.exports [as sync] (/wechaty/node_modules/resolve/lib/sync.js:43:15)
    at resolveStandardizedName (/wechaty/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
    at resolvePlugin (/wechaty/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
    at loadPlugin (/wechaty/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
    at createDescriptor (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:114:9)
    at items.map (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:69:50)
    at Array.map (<anonymous>)
    at createDescriptors (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:69:29)
    at createPluginDescriptors (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:65:10)
    at plugins (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:36:19)_
  ____  _   _  ____   ____  _____ ____   ___  ____ _____  
 | __ )| | | |/ ___| |  _ \| ____|  _ \ / _ \|  _ \_   _| 
 |  _ \| | | | |  _  | |_) |  _| | |_) | | | | |_) || |   
 | |_) | |_| | |_| | |  _ <| |___|  __/| |_| |  _ < | |   
 |____/ \___/ \____| |_| \_\_____|_|    \___/|_| \_\|_|   
                                                          
Press ENTER to continue ... 


### 1. source code of tuling.js

const qrTerm = require('qrcode-terminal')
const Tuling123 = require('tuling123-client')

const {
  Wechaty,
  Message,
} = require('wechaty')

const welcome = `
=============== Powered by Wechaty ===============
-------- https://github.com/Chatie/wechaty --------

I can talk with you using Tuling123.com
Apply your own tuling123.com API_KEY
at: http://www.tuling123.com/html/doc/api.html

__________________________________________________

Please wait... I'm trying to login in...
`

console.log(welcome)

/**
 *
 * Apply Your Own Tuling123 Developer API_KEY at:
 * http://www.tuling123.com
 *
 */
const TULING123_API_KEY = '2d04e14137774829822950ae39025faa'
const tuling = new Tuling123(TULING123_API_KEY)

const bot = new Wechaty()

bot.on('scan',    onScan)
bot.on('login',   onLogin)
bot.on('logout',  onLogout)
bot.on('message', onMessage)
bot.on('error',   onError)

bot.start()
.catch(console.error)

function onScan (qrcode, status) {
  qrTerm.generate(qrcode, { small: true })  // show qrcode on console
}

function onLogin (user) {
  console.log(`${user} login`)
}

function onLogout (user) {
  console.log(`${user} logout`)
}

function onError (e) {
  console.error(e)
}

async function onMessage (msg) {
  // Skip message from self, or inside a room
  if (msg.self() || msg.room() || msg.from().name() === '微信团队' || msg.type() !== Message.Type.Text) return

  console.log('Bot', 'talk: %s'  , msg.text())

  try {
    const {text: reply} = await tuling.ask(msg.text(), {userid: msg.from()})
    console.log('Tuling123', 'Talker reply:"%s" for "%s" ',
                          reply,
                          msg.text(),
            )
    await msg.say(reply)
  } catch (e) {
    console.error('Bot', 'on message tuling.ask() exception: %s' , e && e.message || e)
  }
}
@huan
Copy link
Member

huan commented Aug 11, 2018

Can you try the latest version of v0.19.142 by runing docker pull zixia/wechaty?

I had just tried and it works without any problem.

$ docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty tuling123-bot.js 

 __        __        _           _          
 \ \      / /__  ___| |__   __ _| |_ _   _  
  \ \ /\ / / _ \/ __| '_ \ / _` | __| | | | 
   \ V  V /  __/ (__| | | | (_| | |_| |_| | 
    \_/\_/ \___|\___|_| |_|\__,_|\__|\__, | 
                                     |___/  
____________________________________________________
            https://www.chatie.io
  ____                            _   _             
 / ___|___  _ __  _ __   ___  ___| |_(_)_ __   __ _ 
| |   / _ \| '_ \| '_ \ / _ \/ __| __| | '_ \ / _` |
| |__| (_) | | | | | | |  __/ (__| |_| | | | | (_| |
 \____\___/|_| |_|_| |_|\___|\___|\__|_|_| |_|\__, |
                                              |___/ 
  ____ _           _   ____        _       
 / ___| |__   __ _| |_| __ )  ___ | |_ ___ 
| |   | '_ \ / _` | __|  _ \ / _ \| __/ __|
| |___| | | | (_| | |_| |_) | (_) | |_\__ \
 \____|_| |_|\__,_|\__|____/ \___/ \__|___/
                                           
WECHATY Environment Variables: 1
WECHATY_DOCKER=1

Starting Docker Container for Wechaty v0.19.142 with Node.js v10.8.0 ...
Working directory: /bot
Executing babel-node --presets @babel/env tuling123-bot.js

=============== Powered by Wechaty ===============
-------- https://github.com/Chatie/wechaty --------

I can talk with you using Tuling123.com
Apply your own tuling123.com API_KEY
at: http://www.tuling123.com/html/doc/api.html

__________________________________________________

Please wait... I'm trying to login in...

02:44:23 INFO Wechaty <default> start() v0.19.142 is starting...

@csea007
Copy link
Author

csea007 commented Aug 13, 2018

thanks a lot, the problem above has been fixed after update babel and wechaty. But another issue appeared, could you help me to take a look?

WECHATY Environment Variables: 1
WECHATY_DOCKER=1

Starting Docker Container for Wechaty v0.19.151 with Node.js v10.8.0 ...
Working directory: /bot
Executing babel-node --presets @babel/env tuling.js
/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:138
throw new Error(Plugin/Preset files are not allowed to export objects, only functions. In ${filepath});
^

Error: Plugin/Preset files are not allowed to export objects, only functions. In /bot/node_modules/babel-preset-es2015/lib/index.js
at createDescriptor (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:138:11)
at items.map (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:69:50)
at Array.map ()
at createDescriptors (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:69:29)
at createPresetDescriptors (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:61:10)
at presets (/wechaty/node_modules/@babel/core/lib/config/config-descriptors.js:43:19)
at mergeChainOpts (/wechaty/node_modules/@babel/core/lib/config/config-chain.js:303:26)
at /wechaty/node_modules/@babel/core/lib/config/config-chain.js:266:7
at buildRootChain (/wechaty/node_modules/@babel/core/lib/config/config-chain.js:106:22)
at loadPrivatePartialConfig (/wechaty/node_modules/@babel/core/lib/config/partial.js:55:55)
ERROR: Bot exited with code 1


| __ )| | | |/ | | _ | | _ \ / _ | _ _ |
| _ | | | | | _ | |
) | | | |) | | | | |
) || |
| |
) | |
| | |
| | | _ <| |
| /| || | _ < | |
|
___/ _
/ _| || __|| ___/|| _|_|

Press ENTER to continue ...

1. source code of tuling.js

const qrTerm = require('qrcode-terminal')
const Tuling123 = require('tuling123-client')

const {
Wechaty,
Message,
} = require('wechaty')

const welcome = `
=============== Powered by Wechaty ===============
-------- https://github.com/Chatie/wechaty --------

I can talk with you using Tuling123.com
Apply your own tuling123.com API_KEY
at: http://www.tuling123.com/html/doc/api.html


Please wait... I'm trying to login in...
`

console.log(welcome)

/**
*

*/
const TULING123_API_KEY = '2d04e14137774829822950ae39025faa'
const tuling = new Tuling123(TULING123_API_KEY)

const bot = new Wechaty()

bot.on('scan', onScan)
bot.on('login', onLogin)
bot.on('logout', onLogout)
bot.on('message', onMessage)
bot.on('error', onError)

bot.start()
.catch(console.error)

function onScan (qrcode, status) {
qrTerm.generate(qrcode, { small: true }) // show qrcode on console
}

function onLogin (user) {
console.log(${user} login)
}

function onLogout (user) {
console.log(${user} logout)
}

function onError (e) {
console.error(e)
}

async function onMessage (msg) {
// Skip message from self, or inside a room
if (msg.self() || msg.room() || msg.from().name() === '微信团队' || msg.type() !== Message.Type.Text) return

console.log('Bot', 'talk: %s' , msg.text())

try {
const {text: reply} = await tuling.ask(msg.text(), {userid: msg.from()})
console.log('Tuling123', 'Talker reply:"%s" for "%s" ',
reply,
msg.text(),
)
await msg.say(reply)
} catch (e) {
console.error('Bot', 'on message tuling.ask() exception: %s' , e && e.message || e)
}
}

3. package.json

cat: /bot/package.json: No such file or directory
No package.json

4. directory structor inside /bot/node_modules

ansi-regex babel-plugin-transform-es2015-shorthand-properties inherits
ansi-styles babel-plugin-transform-es2015-spread invariant
asynckit babel-plugin-transform-es2015-sticky-regex isarray
babel-code-frame babel-plugin-transform-es2015-template-literals js-tokens
babel-helper-call-delegate babel-plugin-transform-es2015-typeof-symbol jsesc
babel-helper-define-map babel-plugin-transform-es2015-unicode-regex lodash
babel-helper-function-name babel-plugin-transform-regenerator loose-envify
babel-helper-get-function-arity babel-plugin-transform-runtime methods
babel-helper-hoist-variables babel-plugin-transform-strict-mode mime
babel-helper-optimise-call-expression babel-preset-es2015 mime-db
babel-helper-regex babel-runtime mime-types
babel-helper-replace-supers babel-template mobi.css
babel-messages babel-traverse ms
babel-plugin-check-es2015-constants babel-types private
babel-plugin-transform-es2015-arrow-functions babylon process-nextick-args
babel-plugin-transform-es2015-block-scoped-functions chalk qs
babel-plugin-transform-es2015-block-scoping combined-stream readable-stream
babel-plugin-transform-es2015-classes component-emitter regenerate
babel-plugin-transform-es2015-computed-properties cookiejar regenerator-runtime
babel-plugin-transform-es2015-destructuring core-js regenerator-transform
babel-plugin-transform-es2015-duplicate-keys core-util-is regexpu-core
babel-plugin-transform-es2015-for-of debug regjsgen
babel-plugin-transform-es2015-function-name delayed-stream regjsparser
babel-plugin-transform-es2015-literals escape-string-regexp safe-buffer
babel-plugin-transform-es2015-modules-amd esutils string_decoder
babel-plugin-transform-es2015-modules-commonjs extend strip-ansi
babel-plugin-transform-es2015-modules-systemjs form-data superagent
babel-plugin-transform-es2015-modules-umd formidable supports-color
babel-plugin-transform-es2015-object-super globals to-fast-properties
babel-plugin-transform-es2015-parameters has-ansi util-deprecate

5. wechaty doctor

Wechaty Doctor

  1. Wechaty version: 0.19.151
  2. Linux x64 version 4.9.93-linuxkit-aufs memory 100/1998 MB
  3. Docker: true
  4. Node version: v10.8.0
  5. Tcp IPC TEST: PASS

@huan
Copy link
Member

huan commented Aug 13, 2018

If you are using docker, then you should install neither Wechaty nor Babel because they should be load from docker image.

Try to remove them in your local node_modules directory and try again.

@huan
Copy link
Member

huan commented Aug 13, 2018

It seems we need another getting started for docker users.

Will make one later.

@huan
Copy link
Member

huan commented Aug 13, 2018

@csea007 Can you try our new Docker Getting Started Template at https://github.com/Chatie/docker-wechaty-getting-started?

It should be able to run out-of-the-box.

Please feel free to let me know if it can solve your problem, thanks.

@csea007
Copy link
Author

csea007 commented Aug 15, 2018

Hi zixia,
Thanks for your advices. the issue has been fixed after upgrade Babel from 6 to 7. cheers!

@huan
Copy link
Member

huan commented Aug 15, 2018

Glad to hear that, have a nice day!

@huan huan closed this as completed Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants