after upgrade to V2 code node stopped working (was working fine )
Node execution failed
This can happen for various reasons. Please try executing the node again. If the problem persists, you can try the following:
Reduce the number of items processed at a time, by batching them using a loop node
Increase the memory available to the task runner with ‘N8N_RUNNERS_MAX_OLD_SPACE_SIZE’ environment variable
i added N8N_RUNNERS_MAX_OLD_SPACE_SIZE = 8000 but did not help
here is code, it uses external lib, but it was working just fine
const { DBFFile } = require('dbffile');
const fs = require('fs');
// Path where the new DBF file will be saved
const dbfFilePath = '/home/edmunds/laboratorija/export_.dbf';
fs.unlink(dbfFilePath, (err) => {
if (err) {
console.error(`Error deleting file: ${err.message}`);
} else {
console.log(`File deleted successfully: ${filePath}`);
}
});
// Input data: an array of objects, each representing a record
const inputData = $input.all().map(item => item.json);
// Check if input data is empty
if (inputData.length === 0) {
throw new Error('No input data provided.');
}
// Extract field names and types dynamically from input data
const fields = Object.keys(inputData[0]).map(fieldName => ({
name: fieldName,
type: 'N', // Default type: Character (C) for all fields; customize as needed
size: 10 // Default size for Character fields; adjust based on your needs
}));
async function createDBFFile() {
try {
// Create a new DBF file with the specified fields
await DBFFile.create(dbfFilePath, fields);
// Open the created DBF file
const dbf = await DBFFile.open(dbfFilePath);
// Add records to the DBF file
await dbf.appendRecords(inputData);
return {
message: `DBF file created successfully at ${dbfFilePath}`,
filePath: dbfFilePath
};
} catch (error) {
throw new Error(`Error creating DBF file: ${error.message}`);
}
}
// Run the function and return the output
return await createDBFFile();
Error: Node execution failed at DefaultTaskRunnerDisconnectAnalyzer.toDisconnectError (/home/edmunds/.nvm/versions/node/v20.19.5/lib/node_modules/n8n/src/task-runners/default-task-runner-disconnect-analyzer.ts:32:10) at TaskBrokerWsServer.removeConnection (/home/edmunds/.nvm/versions/node/v20.19.5/lib/node_modules/n8n/src/task-runners/task-broker/task-broker-ws-server.ts:164:58) at WebSocket.<anonymous> (/home/edmunds/.nvm/versions/node/v20.19.5/lib/node_modules/n8n/src/task-runners/task-broker/task-broker-ws-server.ts:148:15) at Object.onceWrapper (node:events:639:26) at WebSocket.emit (node:events:536:35) at WebSocket.emitClose (/home/edmunds/.nvm/versions/node/v20.19.5/lib/node_modules/n8n/node_modules/ws/lib/websocket.js:265:10) at Socket.socketOnClose (/home/edmunds/.nvm/versions/node/v20.19.5/lib/node_modules/n8n/node_modules/ws/lib/websocket.js:1291:15) at Socket.emit (node:events:524:28) at TCP.<anonymous> (node:net:343:12)
Mhh, I think this looks more like it stopped working,because the Code node is doing something that’s not allowed o not available in that runtime.
Probably because your script writes/deletes a file using fs and an absolute path. According to the n8n docs, the Code node isn’t supposed to access the filesystem directly:
They literally say: “You can’t access the file system or make HTTP requests. Use the following nodes instead: Read/Write File From Disk, HTTP Request”.
So I’d try restructuring it like: generate the DBF content/records in the Code node, but do the actual disk write/delete using the “Read/Write Files from Disk” node or another file node instead of fs.
Second thing to check: you’re importing dbffile. External npm modules are only available on self-hosted if you enable them, per the docs here: