Apify Discord Mirror

Updated 5 months ago

Dataset importion problem

At a glance

The community member is using the crawlee package in a Node.js project and is encountering a TypeError: Dataset is not a constructor error. They have tried different approaches, such as changing the import statement and moving the Dataset to a separate require statement, but the issue persists. The community member is unsure if they need to make changes to the package.json file or what the problem might be.

In the comments, another community member suggests that the issue might be related to the use of the import statement outside of a module. They recommend adding the line "type" : "module" at the end of the package.json file to fix this problem.

when using crawlee in a node.js project (npm i crawlee), I keep getting this error with my code :
(cheerio crawler, btw)
TypeError: Dataset is not a constructor

from this section in my scraper code:
const { CheerioCrawler } = require('crawlee');
const Dataset = require('crawlee').dataset;



i changed it from
import { CheerioCrawler, Dataset } from 'crawlee';
to
const { CheerioCrawler } = require('crawlee');

and tried moving the dataset too in its separate require statement but i'm getting this error

this is not in a my-crawler folder and not made with "npx crawlee create my-crawler"
this is node.js project that i downloaded the crawlee package to with "npm i crawlee"
is there something i need to change with the package.json or what's the problem?
L
h
2 comments
Any reason why you don't want to use the, import statement?

Although it will show you an error of "you can't use import outside of a module",

You can fix that by adding this line of code at the end of your package.json file,

"type" : "module"
Add a reply
Sign up and join the conversation on Discord