Waffle icon indicating copy to clipboard operation
Waffle copied to clipboard

"SyntaxError: Cannot use import statement outside a module"

Open Coda-Coda opened this issue 5 years ago • 3 comments

I have tried to follow the steps in README.md under Step by step guide, but run into the error below. (I am new to Node.js)

$ npx mocha test/**/*.test.{js,ts}   
Warning: Cannot find any files matching pattern "test/**/*.test.js"

/root/Waffle/examples/basic/test/BasicToken.test.ts:1
import {expect, use} from 'chai';
^^^^^^

SyntaxError: Cannot use import statement outside a module

I specify the test file format because I hit snags on:

$ npx mocha
Error: No test files found

and

npx mocha --config test/mocha.opts 
failed to parse config "test/mocha.opts": SyntaxError: Unexpected token r in JSON at position 1

It would be great if the README was improved as a result of this issue.

Coda-Coda avatar Aug 11 '20 05:08 Coda-Coda

I followed the getting started instructions and have exactly the same error message, though using a slightly different command to run the test:

npm test test/BasicToken.test.ts

I'm using node v14.4.0 on Ubuntu 20.04.1 LTS.

PreciousChicken avatar Aug 15 '20 17:08 PreciousChicken

I believe this command should work instead: npx mocha -r ts-node/register --timeout 5000 test/*.test.ts. You should add ts-node to devDependencies

ly0va avatar Aug 26 '20 09:08 ly0va

Ok I have the same two problems: no test file found and cannot use import outside of module.

You can fix the first with specifying the ./test/** or whichever folder you placed the tests.

I knocked the second error out by adding tsc to the "test" line of package.json:

"test": "set NODE_ENV=test && tsc && mocha ./test/**.ts"

YannyD avatar Jan 15 '21 01:01 YannyD