Script in package.json with type:"module" and typescript

Viewed 327

I have the following situation:

  1. I need to have "type": "module" in my package.json (ok)

  2. I have a .tsx file that I need to execute as a script. Eg: yarn myScript (ok)

  3. Windows OS (ok)

  4. Node 14.17 (ok)

The problem is that it seems to be harder than it looks.

I have tried the following:

  1. Running with ts-node produced:

    Error: Unknown file extension ".tsx"

  2. Running with node --loader ts-node/esm produced:

    Error: const err = new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(base));

  3. Defining "esModuleInterop": true in tsConfig resulted in nothing being changed.

  4. Trying to transpile with babel and then run node produced:

    Error: require is not defined

  5. Trying to transpile with typescript resulted in many node_modules errors.

Does anyone have any idea or suggestions?

0 Answers
Related