Apify

Apify and Crawlee Official Forum

b
F
A
J
A

Cannot find module after build with typescript

This is my typescript config
Plain Text
{
  "extends": "@apify/tsconfig",
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "node",
    "outDir": "./dist",
    "strict": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "esModuleInterop": true,
    "declaration": true,
    "lib": ["DOM", "DOM.Iterable", "ES2022"]
  },
  "include": ["./src/**/*"]
}

This is my package json
Plain Text
"main": "dist/main.js",
    "engines": {
        "node": ">=16.0.0"
    },
    "scripts": {
        "start": "npm run start:dev",
        "start:prod": "node dist/main.js",
        "start:dev": "./dev.sh && ts-node-esm -T src/main.ts ",
        "build": "tsc",
        "lint": "eslint ./src --ext .ts",
        "lint:fix": "eslint ./src --ext .ts --fix",
        "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
    },


build happening and i see that dist folder created everything fine, but when im trying to run it locally with yarn start:prod i see error (screenshot attachment)

looks like it's trying to reach d.ts file instead of correct routes file not sure how to fix it, i just followed official guide from crawlee dock.
Attachment
image.png
A
P
A
20 comments
It looks like issue happening on configuration level, does author of documentation

https://crawlee.dev/docs/guides/typescript-project
Hello
Try to put *.js on the end of the import path. so it would be something like:
Plain Text
import { router } from './routes.js';
Also I highly suggest you to create a new project with Crawlee CLI
Plain Text
npx crawlee create my-crawler

Which should solve these initial things for you.
Let me try .js is fixing issue, but i need to do it manually? Because i cannot find the way to add .js during bundle
It's a typescript thing, and probably there's a way to add it automatically (some IDE settings), but I just do it manually, yes
Yes i have too many imports to add it manually, it can be a problematic for me to do it manually
As mentioned - I don't have a working solution to do it automatically, so maybe someone else could comment...
It's alright, it started to work

but Input cannot be used anymore by some reasons
Attachment
image.png
how to you get the input though?
I mean - how to you parse it? Any chance you removed INPUT.json by occasion, or something like that?
Im creating input in APIFY panel, and trying to get it from code.
Attachments
image.png
image.png
I used with Apify and it worked this way, now it returns null, should i commit INPUT.json within my code? If yes then how i can change it dynamically?
You need to call await Actor.getInput() after the await Actor.init()
i thought it was for v2
You should still be able to use it the same way as you have it now, but it has to be after Actor.init() call
Actor.init() (besides some other things generally) sets storage client to Apify client in this case. So when you call it before (as you have now) - it tried to fetch input via memory-storage (crawlee default), and Input.json does not exist there, so you get null
Thank you to everyone! I wanted to take a moment to express my gratitude for Apify Crawlee - it's been an incredibly useful tool for our company's scraping needs. We've developed 100 scrapers using Crawlee and Apify, and we're currently in the process of migrating to v3. However, we've encountered some issues along the way that we're working to resolve.

By the way, I had a quick question - is there a limit on the number of actors that can be created with Apify Crawlee? I'd appreciate any insight you can provide. Thank you!
Add a reply
Sign up and join the conversation on Discord
Join