Skip to content
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

Project fails running: uncaught exception, exited with a non-zero exit code #3068

Closed
Tyrben opened this issue Jul 12, 2022 · 2 comments
Closed

Comments

@Tyrben
Copy link

Tyrben commented Jul 12, 2022

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:

    • 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.

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 or ava.config.* configuration files) and how you're invoking AVA. Share the installed AVA version (get it by running npx ava --version).

@novemberborn
Copy link
Member

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?

@dscotese
Copy link

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.

@novemberborn novemberborn closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants