Skip to content

.ts import in CLI Puppeteer TS project results in "Cannot find module" #1618

@galaczi

Description

@galaczi

Which package is this bug report for? If unsure which one to select, leave blank

@crawlee/puppeteer (PuppeteerCrawler)

Issue description

I created a Puppeteer TS project via the CLI. It was weird that routes.js and not routes.ts was imported in main.ts. I tried to import another npm package and failed with the following error message:

/home/Dev/crawlee-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366
    throw new ERR_MODULE_NOT_FOUND(
          ^
CustomError: Cannot find module '/home/Dev/crawlee-playground/src/routes' imported from /home/Dev/crawlee-playground/src/main.ts
    at finalizeResolution (/home/Dev/crawlee-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366:11)
    at moduleResolve (/home/Dev/crawlee-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:801:10)
    at Object.defaultResolve (/home/Dev/crawlee-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
    at /home/Dev/crawlee-playground/node_modules/ts-node/src/esm.ts:218:35
    at entrypointFallback (/home/Dev/crawlee-playground/node_modules/ts-node/src/esm.ts:168:34)
    at /home/Dev/crawlee-playground/node_modules/ts-node/src/esm.ts:217:14
    at addShortCircuitFlag (/home/Dev/crawlee-playground/node_modules/ts-node/src/esm.ts:409:21)
    at resolve (/home/Dev/crawlee-playground/node_modules/ts-node/src/esm.ts:197:12)
    at resolve (/home/Dev/crawlee-playground/node_modules/ts-node/src/child/child-loader.ts:15:39)
    at nextResolve (node:internal/modules/esm/loader:161:28)

Probably a tsconfig error, but I couldn't figure out what's causing it. I can work with importing js files but it's not how I worked with any Ts project in the past.

Code sample

import { PuppeteerCrawler, log, Source, RequestList } from 'crawlee'
import random from 'random'
import Randomstring from 'randomstring'
import { router } from './routes'
import { proxyConfiguration } from './proxyConfiguration'

Package version

^3.0.0

Node.js version

v19.0.0

Operating system

Ubuntu

Apify platform

  • Tick me if you encountered this issue on the Apify platform

Priority this issue should have

Low (slightly annoying)

I have tested this on the next release

No response

Other context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions