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

SyntaxError: Unexpected token export #3

Open
genebean opened this issue Jun 3, 2017 · 0 comments
Open

SyntaxError: Unexpected token export #3

genebean opened this issue Jun 3, 2017 · 0 comments

Comments

@genebean
Copy link

genebean commented Jun 3, 2017

When working on #2 I ran into this error that I don't really understand:

$ SLACK_WEBHOOK=https://hooks.slack.com/services/my-hook-path node server/index.js
/vagrant/server/slack.js:64
export default SlackClient;
^^^^^^
SyntaxError: Unexpected token export
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/vagrant/server/index.js:11:19)

Google & Stack Overflow lead me to believe that it is related to this from https://stackoverflow.com/a/40021867/910874:

You are using ES6 Module syntax.

This means your environment (e.g. node.js) must support ES6 Module syntax.

NodeJS uses CommonJS Module syntax (module.exports) not ES6 module syntax (export keyword).

Solution:

Use babel npm package to transpile your ES6 to a commonjs target
Refactor with CommonJS syntax.

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

1 participant