You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What you're trying to do
Running the tutorial project from the README to test if my set up is OK.
Reproduction:
npm init ava
project.json like in the example
test.js like in the example
npm test
What happened
npm WARN config global --global, --local are deprecated. Use --location=global instead.
> test
> ava
Uncaught exception in test.js
SyntaxError: Cannot use import statement outside a module
× test.js exited with a non-zero exit code: 1
─
1 uncaught exception
What you expected to happen
Tests run and succeed.
This is really trivial. After setting ava in my own project and having the same error, I tried on a blanck projet, just following the example from the README.
Running on Windows, with NodeJS 16.16.0 under a cmd console.
We'll also need your AVA configuration (in package.json or ava.config.* configuration files) and how you're invoking AVA. Share the installed AVA version (get it by running npx ava --version).
The text was updated successfully, but these errors were encountered:
The example uses ESM syntax, but it does not tell you to configure Node.js to use this.
We could change the file format to test.mjs and it'll work out of the box, or give both ESM and CJS examples, at least in the README. What would have helped you the most @Tyrben?
This is the same issue that I just ran into. Part of the problem is that NodeJS 18 documentation says that every file is treated as a module by NodeJS. I have not looked for NodeJS 16 documentation. Windows Subsystem for Linux (WSL) does not (yet?) support NodeJS 18 (WSL does not have GLIBC_2.28 and so produces an error while trying to install NodeJS 18). In any case, NodeJS is clearly viewing the file the docs say to make (test.js) as NOT a module, and therefore disallowing the import statement.
Renaming test.js to test.mjs solves the problem. I don't personally know what the implications of using .mjs are aside from forcing NodeJS 16 to process the file as a module. If anyone has a link to the ins and outs of NodeJS and overall Javascript handling of files, I'd appreciate it being posted.
Please provide details about:
What you're trying to do
Running the tutorial project from the README to test if my set up is OK.
Reproduction:
What happened
Tests run and succeed.
This is really trivial. After setting ava in my own project and having the same error, I tried on a blanck projet, just following the example from the README.
Running on Windows, with NodeJS 16.16.0 under a cmd console.
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
).The text was updated successfully, but these errors were encountered: