Code piece require() suddenly failing. ESM-only now?

Since a few days ago, multiple long-running flows with Code steps that use require() started failing with error:

  • missing ) after argument list

Minimal repro:

// used to work, now fails
const x = require('some-lib');

export const code = async (inputs) => true;

What works now

  • Use ESM imports:
import * as lib from 'some-lib';
  • fs (and other Node core modules) aren’t available in Code;
  • Buffer isn’t global, so:
    • add npm buffer and import { Buffer } from 'buffer', or

Question

Is the Code piece officially ESM-only on Cloud, and which Node built-ins/typings (if any) are supported?

Thanks!

Hi @hanley

Thank you for the detailed reply, I see a breaking where the node types is now not provided by default, the old flows should be migrated to have node deps.

As workaround in mean time, please add this package and it should have exactly old behavior

{
  "dependencies": {
    "@types/node": "18.17.1",
  }
}```

We have it now again pre installed in all sandboxes, sorry for that!

1 Like

Thanks for the quick fix!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.