Open futuremotiondev opened 1 year ago
hey @fmotion1 seems to be a known problem already, I have found the solution here on another thread https://github.com/TypeStrong/ts-node/issues/1997#issuecomment-1537111441 and it worked for me.
@RSchneider94
I managed to solve it:
"type": "module"
from package.json
"module"
value in tsconfig.json
to "module": "commonjs"
along with some other changesTypescript
and ts-node
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.
@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
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
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.
No any solution yet???
This has worked for me on Node 20
node --no-warnings=ExperimentalWarning --loader ts-node/esm file.ts
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.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 aERR_UNKNOWN_FILE_EXTENSION
error. The complete error is here: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
package.json:
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.