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

SyntaxError: Unexpected token #2392

Closed
davidedelvento opened this issue Feb 9, 2020 · 5 comments
Closed

SyntaxError: Unexpected token #2392

davidedelvento opened this issue Feb 9, 2020 · 5 comments

Comments

@davidedelvento
Copy link

I am just trying to get started with AVA and admittedly I have very little experience with javascript in the browser and zero experience with node.js

I'm following the instructions on https://github.com/avajs/ava/blob/master/readme.md namely install and set up AVA, with npm init ava, then Install ava with npm install --save-dev ava then created the very same test.js file as per documentation, attempted to run the test with npm test.

Fails as follows:

davide@buzzicone:~/deleteme$ npm test

> deleteme@1.0.0 test /home/davide/deleteme
> ava

(node:12913) UnhandledPromiseRejectionWarning: /home/davide/deleteme/node_modules/ava/lib/node-arguments.js:9
		} catch {
		        ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.exports.run (/home/davide/deleteme/node_modules/ava/lib/cli.js:261:33)
(node:12913) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12913) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I am pretty sure I must be missing something stupid, but can not find what it is. This is my (basically empty) project:

davide@buzzicone:~/deleteme$ ls
index.js  node_modules  package.json  test.js
davide@buzzicone:~/deleteme$ cat index.js 
function nothing() {
	return 1;
}
davide@buzzicone:~/deleteme$ cat package.json 
{
  "name": "deleteme",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "ava"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "ava": "^3.2.0"
  }
}
davide@buzzicone:~/deleteme$ cat test.js 
const test = require('ava');

test('foo', t => {
	t.pass();
});

test('bar', async t => {
	const bar = Promise.resolve('bar');
	t.is(await bar, 'bar');
});

Besides the fact that I probably do not know what I am doing (which I could learn with a stackoverflow question), a more informative error message would help, hence I am submitting this as a issue here ;-)

@novemberborn
Copy link
Member

I reckon you're using an outdated version of Node.js. AVA 3 requires 10.18 at a minimum. If you have no particular requirements I'd recommend you install Node.js 12.15.

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

@davidedelvento
Copy link
Author

Thanks for the instant answer. I am not installing node.js myself. It came with the OS (Linux) and indeed is v8.10.0.

Shouldn't npm take care of that inconsistent dependency?

@novemberborn
Copy link
Member

Your Node.js version is no longer supported, not even by Node.js.

npm manages dependencies, not Node.js itself.

@davidedelvento
Copy link
Author

Fair enough. I see that ava's package.json has the engines field with the requirement you mentioned. Somewhat I overlooked that when installed. Could you use { "engineStrict" : true } so that would not happen?

Thanks for considering this suggestion.

PS: FWIW, I run an Ubuntu 18.04 which is less than 2 years old and will be around till 2023....

@novemberborn
Copy link
Member

I see that ava's package.json has the engines field with the requirement you mentioned. Somewhat I overlooked that when installed. Could you use { "engineStrict" : true } so that would not happen?

Our engine requirements are advisory only. Sadly, not everybody upgrades at an even pace. Making them mandatory isn't practical for us (but you can configure your npm to enforce it, I believe).

PS: FWIW, I run an Ubuntu 18.04 which is less than 2 years old and will be around till 2023....

I don't maintain Node.js and its dependencies, so I can't help you with that 😄

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

2 participants