Using builtin logging from a Function Node

I’m trying to find the relevant documentation on using builtin logging from a Function Node

I’ve tried the following steps:

  1. Enable support for builtin modules in Function Nodes
    (as per Configuration | Docs)

  2. Import the Logger
    (as per Logging in n8n | Docs)

import {
	LoggerProxy as Logger
} from 'n8n-workflow';

but hit an error
ERROR: Cannot use import statement outside a module

(function (exports, require, module, __filename, __dirname) { module.exports = async function() {import {LoggerProxy as Logger} from 'n8n-workflow';

I’m running:

n8n ready on, port 5678
Version: 0.150.0

I’m guessing this is the issue here:

Also just realised “support for builtin modules in Function Nodes” means Node builtins like fs etc. :man_facepalming:
So would need to enable this configuration instead:

NODE_FUNCTION_ALLOW_EXTERNAL: For external modules sourced from n8n/node_modules directory. External module support is disabled when env variable is not set.


1 Like

Hey @beaspider

Welcome to our forums!

I believe you have it all sorted out, right?

Thanks for posting the solution as well =)

Thanks @krynble
Yes, I misread the documentation :slight_smile:

I now understand that the Function Node is executing the provided JavaScript using NodeVM and also that the documentation on Logging in n8n | Docs was aimed at Developers of n8n not end users writing Expressions / Function Nodes.

I was trying to use the n8n Logger / LoggerProxy in the Function Node but I guess the cleanest way to do that would mean changing the code in the Function.node.ts

    const logger = getLogger();

    // Define the global objects for the custom function
    const sandbox = {