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

"Invalid or unexpected token" at single quotation mark #2204

Closed
Derektvann opened this issue Sep 26, 2019 · 7 comments
Closed

"Invalid or unexpected token" at single quotation mark #2204

Derektvann opened this issue Sep 26, 2019 · 7 comments

Comments

@Derektvann
Copy link

Derektvann commented Sep 26, 2019

I have a problem getting this to work file name : index.js

const express = require(‘express’);
const bodyParser = require(‘body-parser’);
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(3000, () => console.log(‘Webhook server is listening, port 3000));

but when I type node index.js, this is what I get....

Dereks-iMac:msgbot derekvann$ node index.js
/Users/derekvann/Desktop/msgbot/index.js:1
const express = require(‘express’);
                        ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
@bnoordhuis bnoordhuis transferred this issue from nodejs/node Sep 26, 2019
@ORESoftware
Copy link

you are likely using an older node.js version, whereby it doesn't recognize the const keyword.

when you type node -v in the terminal, what do you get?

to install a newer version of node.js on a non-windows machine, I recommend NVM.

@ORESoftware
Copy link

on this note @bnoordhuis it would be kinda neat to display the node.js version in all node.js stacktraces, at the end. think about how much time this would save users debugging etc, and on online messsage boards.

@Derektvann
Copy link
Author

I have Version 10.16.3
is that too old?

@bruce-one
Copy link

That version should support const.

It is possible that the quotes you have are not ' but instead are another character.

Could you try replacing the quotes (eg rewriting them or replacing with double quotes) to see whether that resolves the issue?

The quotes on all the lines look they are rather than '. This is a common issue if copying from sites like Medium which can replace quotes with the "nicer looking" alternatives.

@tniessen
Copy link
Member

@bruce-one is right, you are using some fancy unicode quote characters instead of "normal" single-quotes. If you replace them, it should work.

@tniessen tniessen changed the title Help with Node Please "Invalid or unexpected token" at single quotation mark Oct 13, 2019
@han-so1omon
Copy link

I am having this same error, but it only occurs when splitting a string into multiple lines. When the string is in one line the error goes away.

Error example:

'String 1
is this string
';

Correct example:

'String 2 is this string';

This is using nodejs v12.13.1

@tniessen
Copy link
Member

@han-so1omon That's intentional. If you want line feeds, use the \n escape sequence:

'String 1\nis this string\n';

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

5 participants