[Solved] Unusual ESM import error

Hi.
I have an unusual error with ESM imports that I cannot fathom.
I’m building a workflow that would update the most popular posts in Ghost(Pro) using the analytics data from Fathom Analytics.
Three steps of the workflow are Ghost related. In the first step, I fetch current posts with the tag #popular and in that step, my only ESM import is import GhostAdminAPI from '@tryghost/admin-api'. This step works without any glitches.
In the second step, I’m trying to remove the #popular tag from the posts that I got from the previous step. My only ESM import in this step is also import GhostAdminAPI from '@tryghost/admin-api'. However, here I’m getting an error saying 'import' and 'export' may appear only with 'sourceType: module' (1:0)

So, I have the same ESM imports in two steps, in both cases, they are only ESM imports, and in the first step it works, while in the second step, it produces an error.

Has anyone had similar issues? Any help would be appreciated.

Cheers.

@sinisaperovic This may be related to a subtle bug in our JS parser. Can you check if that second step contains the word “require” anywhere in the step, even in a comment? If so, remove it and try to deploy again. Let me know if that works.

OMG, you were right. There was a “require” in one of the comments, the error is gone now after I removed it.

Thank you very much for your time and effort @dylburger. I’ve lost a few hours on this and now I don’t even care because the solution is out of this world. This I’ll remember :smiley:

Sorry you lost to many hours on it, definitely not intuitive. It is something we’re really hoping to fix!

We just shipped a fix for this issue, so you shouldn’t encounter it in the future. Thanks again for raising.

Thank you @dylburger for your time and effort.

1 Like