Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

368
Visualizações
Async functions not being recognized

I have some async functions that I have used in multiple projects, however when I added them to another project they suddenly aren't working.

An example of one of these functions is:

const ddbGet = async (params) => {
    try {
        const data = await docClient.get(params).promise();
        return data;
    } catch (err) {
        console.log("Failure", err.message);
        return false;
    }
};

The error that gets thrown is:

const ddbGet = async (params) => {

                     ^

SyntaxError: Unexpected token (

However I know there are no problems with the functions' syntax as they are used successfully elsewhere.

I have seen some answers to other questions that have suggested some issues with JSHint and ESLint however I don't believe I was using either of these, but just to be sure I installed ESLint and specified the ECMA version as suggested in those answers and this error was still thrown.

I have also made sure I'm using the latest version of Node.js.

And if I remove those functions an error gets thrown due to an asynchronous function in the node_modules folder.

async handshake(transportName, req, closeConnection) {

   `^^^^^^^^^`

SyntaxError: Unexpected identifier

Does anybody know what the problem could be? Thanks.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Since the documentation, or rather AWS Cloud9's Getting Started isn't kept up-to-date (using an old script to install NVM) and seeing that the project was very old (as per the extended comment section of the question), it surely was the NodeJS version.

This is confirmed by the nvm ls output the OP gave us (I only formatted it):

v6.15.1
-> v17.2.0 system
default -> 6 (-> v6.15.1)
node -> stable (-> v17.2.0) (default)
stable -> 17.2 (-> v17.2.0) (default)
iojs -> N/A (default)
lts/* -> lts/argon (-> N/A) 
lts/argon -> v4.9.1 (-> N/A) 
lts/boron -> v6.17.1 (-> N/A) 
lts/carbon -> v8.17.0 (-> N/A) 
lts/dubnium -> v10.24.1 (-> N/A) 
lts/erbium -> v12.22.9 (-> N/A) 
lts/fermium -> v14.18.3 (-> N/A) 
lts/gallium -> v16.13.2 (-> N/A)

The line default -> 6 (-> v6.15.1) informs us that the default NodeJS version used (for the whole system) is v6.15.1.

Unfortunately, NodeJS does NOT handle async/await syntax natively before v7.6.

You could run nvm install 17.2.0 and then nvm use 17.2.0 (or simply the nvm use part, but I don't know if the v17.2.0 we see in the output have effectively been installed via NVM), which is likely to fix this particular problem.

about 4 years ago · Juan Pablo Isaza Relatório

0

I've found the solution with a little more research after Gaëtan Boyals put me on the right path!

He was correct that the default version of Node.js was the issue and the solution to fix this was nvm alias default 17.2.0

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda