TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.92k stars 532 forks source link

Can't use `--eval` with ESM #2105

Open STRd6 opened 9 months ago

STRd6 commented 9 months ago

Search Terms

input-type=module

Expected Behavior

ts-node -e "import 'package.json'"

import statements should work from CLI.

Actual Behavior

node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_INPUT_TYPE_NOT_ALLOWED]: --input-type can only be used with string input via --eval, --print, or STDIN
    at new NodeError (node:internal/errors:399:5)
    at defaultResolve (node:internal/modules/esm/resolve:1052:25)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at resolve (/home/daniel/.nvm/versions/node/v19.7.0/lib/node_modules/ts-node/dist/child/child-loader.js:15:125)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:416:18)
    at ESMLoader.import (node:internal/modules/esm/loader:517:22)
    at node:internal/modules/run_main:56:28
    at loadESM (node:internal/process/esm_loader:94:11) {
  code: 'ERR_INPUT_TYPE_NOT_ALLOWED'

Steps to reproduce the problem

ts-node -e "import 'package.json'"

Trying with input-type=module also does not work. It is not recognized as an option to ts-node.

https://nodejs.org/api/cli.html#--input-typetype

Minimal reproduction

Specifications

ts-node v10.9.2 node v19.7.0 compiler v5.3.3