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

Chapter 8: Bad syntax in "export getName;" in ESM section #1646

Closed
mirao opened this issue Mar 22, 2020 · 3 comments
Closed

Chapter 8: Bad syntax in "export getName;" in ESM section #1646

mirao opened this issue Mar 22, 2020 · 3 comments

Comments

@mirao
Copy link

mirao commented Mar 22, 2020


Edition: 2nd

Book Title: You Don't Know JS Yet: Scope & Closures - 2nd Edition

Chapter: Chapter 8: The Module Pattern

Section Title: Modern ES Modules (ESM)

Problem:
The statement export getName; doesn't work me with NodeJS 10.x and ESM module (node -r esm client.js), I'm getting "SyntaxError: Invalid or unexpected token".
image

I think the right syntax is export { getName };, see also MDN docs.
Or you can use an alternative suggested by IntelliSense in VScode:

const _getName = getName;
export { _getName as getName };
@mirao
Copy link
Author

mirao commented Mar 22, 2020

This is what I'm getting when using the syntax in your docs:

$ node -r esm client.js 
/home/mirao/workspace/javascript/ydkjs/modules/students.js:3
export getName;
       ^

SyntaxError: Invalid or unexpected token
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

@getify
Copy link
Owner

getify commented Mar 23, 2020

@saebrabaebra you have to unwatch a repository to stop getting notifications on new issues.

@getify
Copy link
Owner

getify commented Mar 23, 2020

@mirao -- sorry, that is a mistake, should have been export { getName };. will fix.

@getify getify closed this as completed in f6e1e05 Mar 23, 2020
Repository owner deleted a comment Jun 22, 2023
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