-
Notifications
You must be signed in to change notification settings - Fork 16
[Q] Proper setup / Cannot use import statement outside a module
#43
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
Comments
AVA enables the source map support built into Node.js so this shouldn't be necessary.
Yea, when set to The generated JS code uses ESM syntax:
However this is a You need to configure TypeScript to output to the CommonJS module syntax, or switch to ESM properly. |
Thank you for your explanation ❤️ I'll try to make a proper setup :) |
Thank you again:
Also, I removed the Time to move to bigger project 🤞 |
Looks like precompiling tests help a lot with time out and speed of tests. Can't confirm 100% - but the only thing that stops me is microsoft/TypeScript#26722 (comment) Overall - it feels like this issue could be closed? Edit: |
Can you help me look at my configuration here? It looks like something went wrong. 🙏 cc @novemberborn |
@liby It is hard to look at your config if you do not share it ;) |
Oh, sorry, I forgot to attach the link |
You use old AVA version - is there any reason why you can't upgrade? What is wrong with your config? Are there any errors? What steps did you try already? |
I am using the latest [email protected], are you reading it wrong?
I got the
To fix the But CI/CD started complaining even before the
So I wonder if I've written my configuration wrong. |
@liby I think you got your config wrong, from the link you shared I see that you have "typescript": {
"rewritePaths": {
"src/": "build/"
},
"compile": false
} But your file structure does not match your your-app/
├─ dist/
│ ├─ tests/
│ │ ├─ myTest.js
├─ tests/
│ ├─ myTest.ts
├─ package.json Then your rewrites would have to be "typescript": {
"rewritePaths": {
"tests/": "dist/tests"
},
"compile": "tsc"
} Note that is required that the value of Looking at your repo you have your tests under "typescript": {
"rewritePaths": {
"__test__": <your-outDir-path-to-tests>
},
"compile": "tsc"
} |
Is this something that has to be done? I disabled it because @novemberborn mentioned that it said “Would be interesting to try with compile: false and precompile” and wanted to try it out. After testing, I feel that |
With it set to false you need to run tsc yourself before running tests. |
Thanks for the reminder. So when I get an |
Typically from what I've seen, compilation through loader extensions can take so long, or fails quietly, that AVA gives up. I always precompile so that the tests are run with JavaScript. Looking at the code, the time taken by |
Because I've been using I also tried to switch to using |
After looking at it, I think there is still a difference between my repo and There may be some other problems in this process, so I may continue to use |
Please provide details about:
Please share relevant sample code. Or better yet, provide a link to a minimal reproducible example.
We'll also need your AVA configuration (in
package.json
orava.config.*
configuration files) and how you're invoking AVA. Share the installed AVA version (get it by runningnpx ava --version
) and@ava/babel
version (from yourpackage.json
file).I try to setup AVA 4 with TS for a bigger project. But to simplify things I reduce the problem to a simply project: https://github.com/sculpt0r/AVAwithTS
Now I try to run

npm run test
. The results is:I tried to follow the documentation of AVA & this plugin:
AVA
(4.3.0
)@ava/typescript
(3.0.1
)source-map-support
- so I did it and in cfg file I added:.tsconfig
theoutDir
is set to the same directory (build
) as in AVA config rewrite pathscompile
is set totsc
, but if I try to run tests withcompile
set onfalse
and thebuild
directory already contains js files - I receive the same results as in the screenshot aboveI assume I'm missing something - but I'm not sure what? Is it possible to take a look at the sample project: https://github.com/sculpt0r/AVAwithTS, then run
npm i
and thennpm run test
.The text was updated successfully, but these errors were encountered: