Is there a way to use AVA with TypeScript + ESM without compile it? #3308
-
| 
         I'm trying to perform a simple error test: npm i -D ava tsx
 import test from "ava";
test("Number should not be a text", (t) => {
  t.deepEqual("1", 1);
});
 {
  "type": "module",
  "ava": {
    "files": [
      "test/**/*.test.ts"
    ],
    "extensions": {
      "ts": "module"
    },
    "nodeArguments": [
      "--import=tsx"
    ]
  },
  "devDependencies": {
    "ava": "^6.1.1",
    "tsx": "^4.7.1"
  }
}
 {
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true
  }
}The above test works if I change from: - "ts": "module"To: + "ts": "commonjs"But, naturally, running it as CJS instead. ❌ Here's the error when running it as  npx ava✅ And here's the file running successfully as  npx ava | 
  
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
| 
         I found a similar issue (not necessarily related), but it looks was closed without a conclusion, despite the PR #3192:  | 
  
Beta Was this translation helpful? Give feedback.
-
        This stacktrace is internal to Node.js. My guess would be that the   | 
  
Beta Was this translation helpful? Give feedback.
-
        
 Regardless, I will mark it as the answer, since this problem does not belong to this repository. @novemberborn, sorry for the inconvenience (and also, thanks!) 🙋🏻♂️  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         I use  "ava": {
	"extensions": {
		"ts": "module"
	},
	"nodeArguments": [
		"--import=tsimp"
	]
} | 
  
Beta Was this translation helpful? Give feedback.
I intentionally avoid this mess myself, using
@ava/typescriptand always running the compiler in a split tab in my terminal.