Skip to content

Error: unknown file extension .ts #1062

Closed

Description

@Thomas1664

Expected Behavior

Load typescript files

Actual Behavior

When I try to execute a typescript file I get the following error message:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/$USERNAME/$PATH_TO_DEV_FOLEDER/index.ts
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
at Loader.getFormat (internal/modules/esm/loader.js:113:42)
at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)
at Loader.import (internal/modules/esm/loader.js:177:17)

Steps to reproduce the problem

launch ts-node index.ts

Minimal reproduction

Specifications

  • ts-node version: v8.10.2 (installed global)
  • node version: v14.3.0
  • TypeScript version:v3.9.3 (installed global)
  • tsconfig.json, if you're using one:
{}
  • Operating system and version: Windows 10 Version 2004
  • If Windows, are you using WSL or WSL2?: Yes, Ubuntu 20.04 LTS in WSL2

Activity

  1. changed the title [-]Error: unknown file extension.ts[/-] on May 30, 2020
  2. cspotcode commented on Jun 2, 2020

    @cspotcode
    Collaborator

    ESM stuff? You might have better luck on our ESM thread. Or post a complete reproduction so someone else can debug.

  3. ascochran commented on Jun 6, 2020

    @ascochran

    I'm having the same issue.

    λ npx ts-node src/app.ts
    TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\$USER\$PATH_TO_DEV_FOLDER\src\app.ts
        at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
        at Loader.getFormat (internal/modules/esm/loader.js:113:42)
        at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)
        at Loader.import (internal/modules/esm/loader.js:177:17)
    
  4. Aguinaldo-Alberto-Naldo commented on Jun 21, 2020

    @Aguinaldo-Alberto-Naldo

    Estou tendo o mesmo problema também

    TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for www\server\src\server.ts at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15) at Loader.getFormat (internal/modules/esm/loader.js:113:42) at Loader.getModuleJob (internal/modules/esm/loader.js:243:31) at Loader.import (internal/modules/esm/loader.js:177:17)

  5. cspotcode commented on Jun 21, 2020

    @cspotcode
    Collaborator
  6. clinkadink commented on Jun 28, 2020

    @clinkadink

    Remove "type": "module" from package.json

  7. SaintPhill commented on Jul 16, 2020

    @SaintPhill

    Remove "type": "module" from package.json

    If remove module type, you cannot use imports in your .ts files

  8. Thomas1664 commented on Jul 16, 2020

    @Thomas1664
    Author

    I must disagree. In Angular projects, there is no "type": "module" in package.json and import synthax works fine. Try to set "module": "es2020" in tsconfig.json

  9. SaintPhill commented on Jul 16, 2020

    @SaintPhill

    I must disagree. In Angular projects, there is no "type": "module" in package.json and import synthax works fine. Try to set "module": "es2020" in tsconfig.json

    nope, same problem with import.
    "Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension."

  10. Thomas1664 commented on Jul 17, 2020

    @Thomas1664
    Author

    I created a template repo which can be used by anyone who has trouble initializing ts-node.

  11. cspotcode commented on Jul 29, 2020

    @cspotcode
    Collaborator

    Closing as this is not a ts-node bug. If you want to use node's native ESM support, which is currently experimental, then you can use ts-node's experimental ESM loader hook. See #1007 for details.

  12. paxperscientiam commented on Dec 10, 2020

    @paxperscientiam

    @clinkadink thanks, that did it for me

  13. 69 remaining items

  14. hellznrg commented on Jun 4, 2024

    @hellznrg

    I got this same error (Unknown file extension ".ts"), trying to run a typescript script with ts-node 10.9.1 and Node 20.10. I couldn't find a solution unfortunately (I tried "esModuleInterop": true in tsconfig), but running the script through tsx worked, so I ended up migrating from ts-node to tsx.

    I find it really odd that .ts files are not recognised by default. Surely ts-node should know how to handle .ts files?

    Switching to tsx was the only thing that worked for me. Now it's as simple as yarn tsx . and BOOM. Not sure what the problem with ts-node is. It's defintely a ts-node problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions