Why Does Importing 'diff' in Node.js Fail with 'Module Does Not Provide an Export Named 'default'' Error?

This topic was automatically generated from Slack. You can find the original thread here.

I am trying to use the node.js ‘diff’ package. At the top of my workflow step I have:
import diff from “diff”;

but this fails with the error: 'The requested module “diff” does not provide an export named ‘default’.

Can you tell me what I am doing wrong?

The error you’re encountering, 'The requested module "diff" does not provide an export named 'default', suggests that the diff package you’re trying to import does not have a default export that you can import using the syntax import diff from "diff";. This is a common issue when dealing with packages that are structured to use named exports or are using the CommonJS module format. In Node.js, especially within the Pipedream environment, you have to be mindful of the module format that a package uses. The diff package likely uses named exports or is a CommonJS module, which means you cannot import it using the default import syntax. To resolve this issue, you can try importing the specific functions you need from the diff package using named imports, if the package supports ECMAScript modules (ESM). For example: import { diffChars } from "diff"; If the package only supports CommonJS, then you would typically use the require syntax. However, within a single step in Pipedream workflows, you can only use import or require statements, not both. Since Pipedream runs on Node.js and encourages the use of ESM imports, you should stick to using import where possible. Given the error message and the constraints within Pipedream, it’s likely that the diff package does not directly support ESM imports in a way that allows for a default import. You should check the documentation for the diff package to see if there are named exports you can use. If the package is primarily a CommonJS module, you might encounter difficulties using it directly with an import statement in Pipedream. If you continue to have trouble, consider looking for alternative packages that offer similar functionality but with better support for ESM, or you might need to adjust your approach to match the export structure of the diff package.

OK, in my case I needed: import { diffLines } from 'diff';