Closed dolsem closed 2 years ago
You'll have to use await import('@ava/cooperate')
instead. You can do that from an async test.before()
hook. It's not ideal but very doable.
@novemberborn unfortunately that doesn't solve the issue because TypeScript transpiles all imports to require statements. If I change module from "commonjs" to "esnext" in tsconfig, running tests starts failing with "Cannot use import statement outside a module".
I've also tried all methods listing in the AVA docs of running TS tests, such as using @ava/typescript
or ts-node
, none of them work for some reason, the only thing I found to work is my current setup with the commonjs
module type.
In our setup at work the dynamic import()
function isn't transpiled.
@novemberborn what's the value of the module
flag in your tsconfig / how do you do transpilation?
I think these may be the relevant properties:
"module": "CommonJS",
"target": "ES2019",
"esModuleInterop": true,
That's just from one service where I know we do dynamic imports.
(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)
@novemberborn I tried it with this configuration, making sure to include "esModuleInterop": true
, but it fails with the same error.
Yea you're right, sorry.
With the upcoming TypeScript 4.7 release you get a node12
module option. It also lets you treat TypeScript files explicitly as CJS or ESM. That way, you can use CJS (but explicitly, through require()
) and still do dynamic import()
.
Shared workers are a new AVA feature and so we've chosen to provide an ESM implementation only.
I run AVA on test files that are precompiled with TypeScript to a commonjs format. I am unable to use this library, getting the following error:
I tried loading using the
esm
package but it doesn't seem to work either.Can you please include commonjs files in your package?
AVA version: 4.1.0. AVA config: