How to access Apify.utils with ES modules?

The docs all have code like the following to use enqueueLinks where you can target a specific request queue.
const Apify = require('apify')
Apify.utils.enqueueLinks({ requestQueue: myQueue })
const Apify = require('apify')
Apify.utils.enqueueLinks({ requestQueue: myQueue })
However this won't work within an ES module project (which is what is setup when you use the actor starter templates!). I've tried import {utils} from 'apify' but there does not appear to be a named export like that. How do I access this API? All the docs seem to be referencing CJS which should probably be updated if the official templates are not using this. I looked at the type for the requestHandler contextual enqueueLinks and it appears to omit the requestQueue property so cannot override there.
6 Replies
automatic-azure
automatic-azure•10mo ago
Hello @Yam, it seems youre checking an old documentation to v2 SDK, this is the current documentation to v3 (crawlee SDK): https://crawlee.dev/docs/quick-start. In crawlee, the enqueueLinks helper is directly in the context object. You can check for example this: https://crawlee.dev/docs/examples/crawl-relative-links.
adverse-sapphire
adverse-sapphireOP•9mo ago
Hey, thanks, I see. I can't quite find in these docs still what I'm trying to do. I want to enqueue the links to a specific request queue, not the same one that is being processed in context ie. what is the v3 (/ES) equivilent of using Apify.utils.enqueueLinks where you can specify requestQueue with an option? As an aside, something I'm finding hard to fully grapple with is when should I be using an export from 'apify' vs from 'crawlee' - for example Dataset is exported from both and I'm using the apify version (eg. Dataset.open(name)) but wondering if I'm supposed to use the crawlee version for "portability" or other reasons. Same with RequestList. I'm finding the intersection of crawlee and apify apis somewhat confusing (admittedly I may be over thinking things, but coming to it as a newbie I keep finding multiple ways to do seemingly the same thing with subtle or not differences) Hey @vojtechmaslan any ideas? The context enqueueLinks omits the requestQueue option so cannot be used in the same way utils.enqueueLinks could and I cannot find any documented alternative.
MEE6
MEE6•9mo ago
@Yam just advanced to level 1! Thanks for your contributions! 🎉
automatic-azure
automatic-azure•9mo ago
Hello @Yam, sorry, I didn't notice the enqueueLinks from context omitted the requestQueue option. You should then be able to use enqueueLinks exported from crawlee import { enqueueLinks } from 'crawlee';. To answer your second question, for cases when you have same exports both in apify and crawlee you can choose either of them, the reason for this is, that you should be able to use either package without the other one.
adverse-sapphire
adverse-sapphireOP•9mo ago
Great, I'll give that a go. Thanks for the response!

Did you find this page helpful?