n8n · Code node

'import' and 'export' may only appear at the top level

Short answer

This n8n Code node error occurs if you use import or export, which the n8n JavaScript sandbox does not support. Change your import statements to use require, for example const express = require("express");.

VerifiedLast verified

01Error text

n8n error
'import' and 'export' may only appear at the top level

02Likely causes

  • The code uses import or export. These aren't supported by n8n's JavaScript sandbox.

03How to fix it

  1. Change your import statements to use require, for example const express = require("express");.

04Official documentation

Test every fix in a non-production environment before you apply it to production. See how entries are verified.

More for n8n work:Open n8n jobsn8n rates and salaries

The iPaaS Brief

Subscribe to The iPaaS Brief.

The iPaaS newsletter for the people who run integrations. From iPaaS Group.

Free. You finish on theipaasbrief.com and confirm by email.