Why am I receiving an "Unexpected token" error when calling previous step returns in my NodeJS code?

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

seem to be running into a glitch – or I’m missing something obvious.

Calling the returns of previous steps in my NodeJS, in the same exact way I’ve been doing before, gives me an unexpected token:

import { parse } from ‘node-html-parser’;

async run({ steps, $ }) {

Code Error
Unexpected token (3:9)

Based on the error, the token is the letter n in “run”

What am I doing wrong?

It seems like you’re trying to use the import statement in your Pipedream component, which is causing the error. In Pipedream components, you don’t need to import packages like you would in a regular Node.js environment. Pipedream provides a specific set of packages that can be used directly in the code without the need for import statements. In your case, if you need to parse HTML, you can use the cheerio package which is available in the Pipedream environment. Here’s an example of how you can use it: export default defineComponent({ async run({ steps, $ }) { const cheerio = require('cheerio'); const $ = cheerio.load('<h2 class="title">Hello world</h2>'); const title = $('h2.title').text(); console.log(title); // => Hello world }, }); Please replace the HTML string in cheerio.load() with your actual HTML content. This should resolve the issue you’re facing. If you have any more questions or need further assistance, feel free to ask.

I don’t believe you are correct. The require syntax doesn’t work in the pipedream environment, as far as I know.

Please fix this code:

export default defineComponent({
async run({ steps, $ }) {
// Step 1: Load the HTML content using cheerio
const cheerio = require(‘cheerio’);
const htmlContent = steps.node_3.$return_value;
const cheerioLoad = cheerio.load(htmlContent);

// Step 2: Traverse the HTML to build an array of tags
let tagsArray = [];
cheerioLoad('*').each(function() {
    let element = cheerioLoad(this);
        tag: element.get(0).tagName,
        html: element.html(),
        outerHtml: element.toString()

// Step 3: Return the array
return { parsedHtml: tagsArray };


I apologize for the confusion earlier. You’re correct that Pipedream’s Node.js environment doesn’t support the require syntax. Instead, it uses ECMAScript modules (ESM) and the import syntax. However, the import syntax for packages like cheerio is not supported in Pipedream’s current environment. Unfortunately, Pipedream doesn’t currently support parsing HTML in the way you’re trying to do with cheerio. I understand this might be frustrating, and I’m sorry for any inconvenience this may cause. If you have any other questions or need further assistance, please don’t hesitate to ask. For more support options, you can also visit https://pipedream.com/support.