Hello everyone,
I’m experiencing a strange issue with my custom n8n nodes. Locally everything works fine, but in the test environment I get this error:
NodeApiError: nativeProtocol.request is not a function
I’m using a helper function pattern
// Helper functions
export function getMakeAxiosRequestFunction(
functions: IExecuteFunctions,
pairedItem: INodeExecutionData['pairedItem'],
): {
(request: {
(): Promise<AxiosResponse<unknown, unknown>>;
}): Promise<INodeExecutionData[] | NodeExecutionWithMetadata[]>;
} {
return async (request) => await handleRequest(request, functions, pairedItem);
}
export async function handleRequest(
request: { (): Promise<AxiosResponse<unknown, unknown>> },
functions: IExecuteFunctions,
pairedItem: INodeExecutionData['pairedItem'],
): Promise<INodeExecutionData[] | NodeExecutionWithMetadata[]> {
try {
// ... success handling
} catch (e) {
const error = new NodeApiError(functions.getNode(), e as unknown as JsonObject, {
message: e.message,
httpCode: axios.isAxiosError(e) ? e.response?.status?.toString() : undefined,
});
// ... error handling
}
}
In my custom node implementation, I call:
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
// rest code ...
const axiosInstance = axios.create({
baseURL: credentials.baseUrl,
});
for (let i = 0; i < items.length; i++) {
// rest code ...
const makeRequest = getMakeAxiosRequestFunction(this, i);
// rest code ...
if (operation === 'someName') {
returnData.push(
await makeRequest(async () => await axiosInstance.get('/api/example/data')),
);
}
}
}
Questions
- Could this be related to race conditions or parallel execution in multi-main setups?
- Are there known issues with NodeApiError constructor in certain n8n environments?
- Is there something wrong with my approach to error handling in helper functions?
Any help would be greatly appreciated!
Thanks
What is the error message (if any)?
NodeApiError: nativeProtocol.request is not a function
Share the output returned by the last node
Information on your n8n setup
- n8n version: 2.4.6
- Database (default: SQLite):Postgres
- n8n EXECUTIONS_PROCESS setting (default: own, main):-
- Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
- Operating system:-
