Current behavior
I faced intricate issue, posted on SOF before: https://stackoverflow.com/questions/65164157/set-up-testing-library-react-with-mocha-got-syntaxerror-unexpected-token
Please clone this repo: https://github.com/inovramadani/babel-bug
And then run npm test
Should get this error:
import Button from './button';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Expected behavior
Should be able to run the test smoothly and not getting any error.
Environment
Tried on 3 different OS-es and 3 different npm and node versions, got same error. So I think has nothing to do with the environment.
I think you have to use require for importing
const Button = require('./button');
I found this about compiling ES6 import statement
https://stackoverflow.com/questions/59042716/trying-es6-style-import-gives-cannot-use-import-statement-outside-a-module
Seems to be answered in: https://github.com/babel/babel/discussions/12463.