apify / apify-docs

This project is the home of Apify's documentation.
https://docs.apify.com
Apache License 2.0
22 stars 69 forks source link

Error when following Professional scraping tutorial #1063

Open tomnosek opened 2 weeks ago

tomnosek commented 2 weeks ago

When following instructions here, the following error is thrown:

(node:38508) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)

import { CheerioCrawler } from 'crawlee';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1281:20)
    at Module._compile (node:internal/modules/cjs/loader:1321:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49

The error is fixed by adding the following attributes to package.json:

"main": "crawlee.js",
"type": "module",

That should likely go after the code example in the "After" paragraph, before the "Then" paragraph.

B4nan commented 2 weeks ago

Hmm, good point, we adopted ESM import syntax in the examples but we haven't really described that you need ESM project for that and how to set it up.

We should add a block like the one in crawlee docs.

image