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

use babel-node to run javascript(.js) file inside docker #507

Closed
huan opened this issue May 12, 2017 · 2 comments
Closed

use babel-node to run javascript(.js) file inside docker #507

huan opened this issue May 12, 2017 · 2 comments

Comments

@huan
Copy link
Member

huan commented May 12, 2017

When we run mybot.js by Docker, we might get this error message:

Executing node mybot.js
/bot/mybot.js:1
import {
^^^^^^
SyntaxError: Unexpected token import

This is because Wechaty use node instead of babel to run js code, which does not support import.

Solution:

use Babel Node to run javascript code inside docker to support ES6/7.

Thanks @ jaf(weixin://wxwswjws) report this.

@huan
Copy link
Member Author

huan commented May 15, 2017

Let's use babel-node by default, and use node only when NODE_ENV is production.
See: http://stackoverflow.com/questions/16978256/what-is-node-env-in-express

According to http://babeljs.io/docs/usage/cli/#babel-node

Not meant for production use
You should not be using babel-node in production. It is unnecessarily heavy, with high memory usage due to the cache being stored in memory. You will also always experience a startup performance penalty as the entire app needs to be compiled on the fly.

Check out the example Node.js server with Babel for an idea of how to use Babel in a production deployment.

@huan
Copy link
Member Author

huan commented May 15, 2017

Done.

https://circleci.com/gh/Chatie/wechaty/1661

ok 3 javascript es6 import should success
ok 4 javascript es6 import with NODE_ENV=production should fail

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

No branches or pull requests

1 participant