Apify Discord Mirror

Updated 5 months ago

Error: Error: Cannot find module '/home/myuser/dist/main.js'

At a glance

The community member is experiencing an error when trying to run a successful build for their Apify actor, but the build works locally without any issues. They have disabled linting and warnings to resolve the TypeScript compilation errors. The community members suggest that the issue might be related to the Docker build not placing the built JavaScript files in the correct location. They share their Dockerfile and changes made to the tsconfig file to disable unused variable warnings. One community member suggests using the "NodeNext" module option in the tsconfig file or updating the Apify CLI to the latest version and regenerating the project from the template.

Useful resources
I am getting the error: Error:
Plain Text
 Cannot find module '/home/myuser/dist/main.js' 

when trying to run a successfull build for my actor on Apify, but locally it works without errors.
I have disabled a lot of linting and warnings as they serve me no real purpose other than stop my typescript compliation from succeeding.
It is a Typescript Crawlee project.

Do you have any idea of what might be the cause?
2
o
L
C
9 comments
Hi, it looks like docker build doesn't put built js files to the right place. Could you share the content of your Dockerfile?
You must have changed something from the template
Hmm I will try to delve into what might be changed
I have done the cahnges in tsconfig to try to disable warnings for unused variables as this should not make compilation fail as it is just a warning
not a critical error
did you ever fix this? I'm running into same issue
I gues for module options You should use "NodeNext":
Plain Text
{
    "extends": "@apify/tsconfig",
    "compilerOptions": {
        "module": "NodeNext",
        "moduleResolution": "NodeNext",
        "target": "ES2022",
        "outDir": "dist",
        "noUnusedLocals": false,
        "skipLibCheck": true,
        "lib": ["DOM"]
    },
    "include": [
        "./src/**/*"
    ]
}


Otherwise, just update apify-cli to the latest version and regenerate it from the template.
Add a reply
Sign up and join the conversation on Discord