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

ERR_UNKNOWN_FILE_EXTENSION no matter what I do. #2033

Open
futuremotiondev opened this issue Jul 4, 2023 · 7 comments
Open

ERR_UNKNOWN_FILE_EXTENSION no matter what I do. #2033

futuremotiondev opened this issue Jul 4, 2023 · 7 comments

Comments

@futuremotiondev
Copy link

Search Terms

ERR_UNKNOWN_FILE_EXTENSION
Unknown file extension ".ts"

I've tried re-installing ts-node over and over again, both globally and in scope of my project. No matter what I do, I hit the ERR_UNKNOWN_FILE_EXTENSION wall.

I've read through the documentation here about the error, and none of the suggestions have fixed my problem.

I've tried:

ts-node-esm ExportSVGsFromJSON.ts
ts-node --esm ExportSVGsFromJSON.ts

I am on v10.9.1 of TS-Node.

You have moved your project to ESM but still have a config file, such as webpack.config.ts, which must be executed as CommonJS

I have not moved my project to ESM and have no config other than tsconfig.json.

Essentially, none of the suggestions have helped.

The kicker is that I actually had this working fine a few hours ago, but now its failing after a fresh reinstall.

Expected Behavior

ts-node .\ExportSVGsFromJSON.ts executes my TypeScript file.

Actual Behavior

ts-node .\ExportSVGsFromJSON.ts throws a ERR_UNKNOWN_FILE_EXTENSION error. The complete error is here:

07-04 06:46:58 D:\Dev\Node\Projects\Iconify> ts-node .\ExportSVGsFromJSON.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\Dev\Node\Projects\Iconify\ExportSVGsFromJSON.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 DefaultModuleLoader.load (node:internal/modules/esm/loader:320:26)
    at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:195:22)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)
    at DefaultModuleLoader.#createModuleJob (node:internal/modules/esm/loader:219:17)
    at DefaultModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:172:34)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:157:17) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

Steps to reproduce the problem

npm install @iconify/tools --save
npm install @iconify/utils --save
npm i @iconify/types
npm install typescript --save-dev
npm install -D ts-node (or Globally, the result is the same)

Run ts-node .\ExportSVGsFromJSON.ts

Minimal reproduction

Install Iconify utils and tools, typescript, and ts-node. Try to run a TS script with ts-node.

Specifications

  • ts-node version: v10.9.1
  • node version: v20.1.0 (But I have nvm with two other versions)
  • TypeScript version: v5.1.6
  • tsconfig.json, if you're using one:
{
   "compileOnSave": true,
   "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "declaration": false,
      "noImplicitAny": false,
      "moduleResolution": "node",
      "preserveConstEnums": true,
      "removeComments": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "sourceMap": true,


      "lib": ["es2015", "dom"],
      "baseUrl": "./",
      "typeRoots": [
          "node_modules/@types"
      ],
      "types": [
        "node"
      ],
      "paths": {
        "src/*": ["src/*"]
      }

   },

   "exclude": [
        "node_modules",
        "dist",
        "build"
    ],
    "filesGlob": [
        "./src/**/*.ts",
        "./test/**/*.ts",
        "./typings/index.d.ts",
        "./custom_typings/**/*.d.ts",
        "./node_modules/@types/**/*.d.ts"
    ]
}
  • package.json:
{
  "type": "module",
  "dependencies": {
    "@iconify/json": "^2.2.85",
    "@iconify/tools": "^3.0.2",
    "@iconify/utils": "^2.1.7"
  },

  "devDependencies": {
    "@types/node": "^20.3.3",
    "ts-node": "^10.9.1",
    "tslib": "^2.6.0",
    "typescript": "^5.1.6"
  }
}
  • Operating system and version: Windows 10 Pro x64 22H2
  • If Windows, are you using WSL or WSL2?: No

I could really use some help here. I had this working nearly 2-3 hours ago and I must have messed something up. I also noticed that @iconify/json was updated in the last 6 hours. Maybe that has something to do with it.

If someone can point me in the right direction that would be a lifesaver.

Thank you.

@RSchneider94
Copy link

hey @fmotion1 seems to be a known problem already, I have found the solution here on another thread #1997 (comment) and it worked for me.

@futuremotiondev
Copy link
Author

futuremotiondev commented Jul 6, 2023

@RSchneider94

I managed to solve it:

  1. Removed "type": "module" from package.json
  2. Changed the "module" value in tsconfig.json to "module": "commonjs" along with some other changes
  3. Removed all global installs of Typescript and ts-node
  4. I now run my command with npx ts-node '.\ExportSVGsFromJSON.ts'

This is what worked for me. I think the key was removing the module declaration from package.json.

Here's my full package.json:

{
  "dependencies": {
    "@iconify/json": "^2.2.85",
    "@iconify/tools": "^3.0.2",
    "@iconify/types": "^2.0.0",
    "@iconify/utils": "^2.1.7",
    "iconify": "^1.4.0",
    "winston": "^3.9.0"
  },
  "scripts": {
    "dev": "npx ts-node ./ExportSVGsFromJSON.ts"
  },
  "devDependencies": {
    "@types/node": "^20.3.3",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.6"
  }
}

And here's my full tsconfig.json:

{
    "compilerOptions": {
        "target": "es6",
        "skipLibCheck": true,
        "lib": [
            "ES6",
            "dom"
        ],
        "rootDir": ".",
        "module": "commonjs",
        "esModuleInterop": true,
        "moduleResolution": "node",
        "strict": true,
        "declaration": false,
        "sourceMap": true,
        "inlineSources": true,
        "types": [
            "node"
        ],
        "stripInternal": true,
        "incremental": true,
        "skipDefaultLibCheck": true,
        "inlineSourceMap": false,
        "noEmit": false
    },
    "include": [
        "./**/*"
    ],
    "exclude": [
        "node_modules"
    ],
    "ts-node": {
        "cwd": ".",
        "projectSearchDir": ".",
        "require": [],
        "project": "./tsconfig.json"
    }
}

I try to avoid installing global packages for portability concerns.

Really hope this manages to help some folks out there.

Edit:

tsx also works fine for me out of the box.

@RSchneider94
Copy link

@fmotion1 hmmm yeah, removing the "type": "module" should work for sure.. but the problem is that some projects need this, because we are using/importing some libs that requires us to use this.. and then it's where the problems starts, and as far as I researched until now, the link I have sent above is the only way to make it work again, it seems that something broke with Node v20

@ThePlenkov
Copy link

I think is a bug. I also tried all the variants and ts-node doesn't work with type: module. However when I tried to run node --loader ts-node/esm index.js with code like

import 'index.ts'

then it works as expected

@jszklarz
Copy link

Specifications

  • ts-node version: v10.9.1
  • node version: v20.1.0 (But I have nvm with two other versions)
  • TypeScript version: v5.1.6
  • tsconfig.json, if you're using one:

I experienced this just now and it was due to being on node20. Going back to node18 solved it for me.

kodiakhq bot pushed a commit to shadcn-ui/ui that referenced this issue Jan 28, 2024
…1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
@SalahAdDin
Copy link

No any solution yet???

@wolfy1339
Copy link

This has worked for me on Node 20

node --no-warnings=ExperimentalWarning --loader ts-node/esm file.ts

frontbest0726 added a commit to frontbest0726/shadcn-ui that referenced this issue Apr 26, 2024
…#1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
PhantomDev007 added a commit to PhantomDev007/Radix-ui-Tailwind-CSS that referenced this issue May 4, 2024
…#1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
kjxbyz pushed a commit to muse-ui/muse-ui that referenced this issue Jun 7, 2024
…hadcn-ui#1977)

This pull request resolves shadcn-ui#1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in shadcn-ui#1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on shadcn-ui#1937. That will not happen again.
Julien712-dev added a commit to Julien712-dev/custom-ui that referenced this issue Aug 6, 2024
…#1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
dev-arrow added a commit to dev-arrow/ui that referenced this issue Nov 27, 2024
…#1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants