Error message after testing code

Carlos Melo

Member
Hello guys,
I'm working with OpanAI to create a code that can send data to a spreadsheet, respecting some rules.
However, in my tests, I've been receiving the following message:

"You cannot import node modules or use eval() in your code. We have already imported Node modules like 'crypto-js', 'lodash', and 'moment' into the wrapper function for you. To use them call these predefined variables: CryptoJS, _, moment respectively.”

That is the code Opan AI sent me:


const { google } = require('googleapis');
const sheets = google.sheets('v4');

// Captura as credenciais da variável de ambiente
const credentials = JSON.parse(process.env.appbikus); // Variável de ambiente criada no Pabbly

// Função de autenticação
async function autenticar() {
const authClient = new google.auth.GoogleAuth({
credentials: credentials,
scopes: ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'],
});
return authClient;
}

// Função para inserir dados em uma única aba
async function inserirDados(linhaInserida, abaSelecionada, dados) {
const authClient = await autenticar();
const spreadsheetId = 'SEU_SPREADSHEET_ID'; // Insira o ID da sua planilha aqui

// Define o intervalo (range) na aba selecionada, da coluna A até L
const range = `${abaSelecionada}!A${linhaInserida}:L${linhaInserida}`;

// Inserir o número da linha na coluna A e os dados de B a L
await sheets.spreadsheets.values.update({
auth: authClient,
spreadsheetId,
range,
valueInputOption: 'USER_ENTERED',
resource: {
values: [[linhaInserida, ...dados]], // Número da linha na coluna A e dados nas colunas B a L
},
});
}

// Dados de exemplo vindos do Jotform (mapeados para as colunas B a L)
const dados = [
'Joana', // Nome (Coluna B)
'123456789', // Whatsapp (Coluna C)
'123.456.789-00', // CPF (Coluna D)
'TI', // Segmento de Atuação (Coluna E)
'5 anos', // Experiência Profissional (Coluna F)
'4.5', // Avaliação (Coluna G)
'link_da_foto.jpg', // Foto (Coluna H)
'Python, JS', // Cursos (Coluna I)
'[email protected]', // E-mail (Coluna J)
'Rua X, 123', // Endereço (Rua e Número) (Coluna K)
'Bairro Y, Cidade Z' // Endereço (Bairro e Cidade) (Coluna L)
];

const linhaInserida = 5; // Número da linha a ser inserida
const abaSelecionada = 'Garçom'; // Exemplo: aba "Garçom"

// Chama a função para inserir os dados na aba especificada
inserirDados(linhaInserida, abaSelecionada, dados).catch(console.error);




Could someone tell me why I am receiving that error message ?
 

ArshilAhmad

Well-known member
Staff member
Are you able to execute this code successfully in an online JS compiler? If you are facing issues with the online compiler as well, then I’m afraid we won’t be able to assist you with coding-related issues, as it is beyond our scope of expertise.
1726690697791.png
 
Top