Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local execution of TypeScript Actors broken in Node 20 #368

Closed
wodow opened this issue May 31, 2023 · 3 comments
Closed

Local execution of TypeScript Actors broken in Node 20 #368

wodow opened this issue May 31, 2023 · 3 comments
Assignees
Labels
t-tooling Issues with this label are in the ownership of the tooling team.

Comments

@wodow
Copy link

wodow commented May 31, 2023

Minimal reproduction:

❯ apify create
? Name of your new actor: test-ts-actor
? Choose the programming language of your new actor: TypeScript
? Choose a template for your new actor. Detailed information about the template will be shown in the
next step. Start with TypeScript
? Do you want to install the following template?
Start with TypeScript:
A simple TypeScript example of core Actor and Apify SDK features. It reads and validates user input
with schema, computes a result and saves it to storage. Install template
Run: npm install
added 149 packages, and audited 150 packages in 14s
31 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Success: Actor 'test-ts-actor' was created. To run it, run "cd test-ts-actor" and "apify run".

Then, doing what it asks:

❯ apify run
Run: npm start

> [email protected] start
> npm run start:dev


> [email protected] start:dev
> ts-node-esm -T src/main.ts

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for <SNIP>/test-ts-actor/src/main.ts
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:99:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:139:38)
    at defaultLoad (node:internal/modules/esm/load:83:20)
    at nextLoad (node:internal/modules/esm/hooks:735:28)
    at load (<SNIP>/test-ts-actor/node_modules/ts-node/dist/child/child-loader.js:19:122)
    at nextLoad (node:internal/modules/esm/hooks:735:28)
    at Hooks.load (node:internal/modules/esm/hooks:380:26)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:165:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:762:20) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Error: npm exited with code 1

This is on latest MacOS with Node 20 installed from Brew/Homebrew.

Downgrading to Node 18 (latest LTS) resolves the problem.

@wodow
Copy link
Author

wodow commented May 31, 2023

A recent SO post suggested this issue thread: TypeStrong/ts-node#1997

@B4nan
Copy link
Member

B4nan commented May 31, 2023

Sounds like a ts-node issue, not really about the CLI (that just runs npm start for you). I guess you get the same problem when you do npm start or run the command that it wraps (so ts-node-esm -T src/main.ts)?

Does node --loader ts-node/esm src/main.ts work? That's what people suggest in the issue you linked.

@gippy gippy added the t-tooling Issues with this label are in the ownership of the tooling team. label Jun 5, 2023
@B4nan
Copy link
Member

B4nan commented Jul 4, 2023

Closing as there was no response, from my experience with this problem from other projects, the node --loader will do the job.

edit: this is actually already resolved in the template, and the ts-node-esm did the job

@B4nan B4nan closed this as completed Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-tooling Issues with this label are in the ownership of the tooling team.
Projects
None yet
Development

No branches or pull requests

3 participants