Basic installation fails on ava test with typescript is giving me the below stacktrace.
import test from 'ava'
test('one plus two equals three', t => {
t.is(1 + 2, 3)
})
/Volumes/1TBDrive/WorkingSet/******/nuxt-static-web/test/index.test.ts:1
import test from '../node_modules/ava';
^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:703:23)
at Module.m._compile (/Volumes/1TBDrive/WorkingSet/******/nuxt-static-web/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at require.extensions.<computed> (/Volumes/1TBDrive/WorkingSet/******/nuxt-static-web/node_modules/ts-node/src/index.ts:442:12)
at Object.require.extensions.<computed> [as .ts] (/Volumes/1TBDrive/WorkingSet/******/nuxt-static-web/node_modules/ava-ts/lib/process-adapter.js:100:4)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Module.require (internal/modules/cjs/loader.js:666:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/Volumes/1TBDrive/WorkingSet/******/nuxt-static-web/node_modules/ava-ts/lib/test-worker.js:65:1)
tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"lib": [
"esnext",
"esnext.asynciterable",
"dom"
],
"esModuleInterop": true,
"experimentalDecorators": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noImplicitAny": false,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
],
"@/*": [
"./*"
],
"~/components/*": [
"./components/*"
]
},
"types": [
"@types/node",
"@nuxt/vue-app"
]
}
}
package.json
{
"dependencies": {
...
"ava": "^1.4.1",
"ts-node": "^8.1.0",
},
"ava": {
"compileEnhancements": false,
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
}
}
Tell us which operating system you are using, as well as which versions of Node.js, npm, and AVA. Run the following to get it quickly:
Node.js v12.2.0
darwin 18.5.0
ava v1.4.1
npm v6.9.0
"target": "esnext",
You've configured TypeScript to emit ESM syntax, which Node.js does not yet support. If possible you should change the target when running tests, but I'm not sure how that'd work with ts-node. You could also try the esm package but again I'm not sure how that interacts with ts-node.
(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)
Possible solution for anyone who's looking:
"module": "es2015" from your tsconfig.jsontsc --module es2015 whenever you call tsc _to build_ (as opposed to _to test_)$ tsc directly, pass the TS config in the build file. Webpack example: https://github.com/sindresorhus/refined-github/blob/0b40361983b362d028fac2fe0fed9486134fa41e/webpack.config.ts#L69-L70I am having the same issue, and I don't use Typescript, or any compiler at all.
node -v
v10.15.2
AVA does not support ES modules, you鈥檒l need to add the esm package like explained in the docs.
AVA does not support ES modules, you鈥檒l need to add the
esmpackage like explained in the docs.
Where exactly? I was reading readme.md and it seems to dive right into the example, no mention of this prerequisite. Also not trace of this prerequisite in the sample package.json given:
{
"name": "awesome-package",
"scripts": {
"test": "ava"
},
"devDependencies": {
"ava": "^1.0.0"
}
}
I was just following instructions from readme.md
import test from 'ava';
test('foo', t => {
t.pass();
});
I googled it sweat_smile
Thank you very much!
I understand now, the issue was that I was trying to do node test.js or node test.mjs thinking that eh, it's gotta be the same than doing `npm bin`/ava or ava. It's not.
Most helpful comment
Where exactly? I was reading
readme.mdand it seems to dive right into the example, no mention of this prerequisite. Also not trace of this prerequisite in the samplepackage.jsongiven:I was just following instructions from
readme.md