I'm getting SyntaxError: Unexpected token import
on my setup file for my Jest tests. I know the fix is via the .babelrc
file. This actually works in some cases. I copy pasted it from https://github.com/zeit/next.js/tree/canary/examples/with-jest.
When I run npm test
, it fails. When I run npm run test
, it also fails. When I run npm run test:coverage
, it works. My scripts are these:
"test": "NODE_ENV=test jest",
"test:coverage": "NODE_ENV=test jest --coverage --coverageDirectory=coverage",
If I change test:coverage
to just NODE_ENV=test jest
, that fails. So somehow requesting a coverage report magically fixes the issue.
Strangely, the coverage one was failing while the basic one was working. I removed my package lock, removed modules, and tried npm install
again. Then the fail cases reversed to what I wrote above.
My setup file is this:
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import jestFetch from 'jest-fetch-mock';
configure({ adapter: new Adapter() });
global.fetch = jestFetch;
I've modified the Nextjs sample app to be nearly identical, yet the error doesn't appear. I have no idea what the difference could be.
UPDATE
I literally copied all contents of the sample and it still didn't work. I then RENAMED my folder from my-app
to my-appy
and it did work. I went back all my original code, including the folder name my-app
and it failed. I renamed the folder and it worked. How is the folder impacting what happens when I run npm test
UPDATE 2
Other people downloading my repo have no issue. Have never run into an issue with a folder name quite like this.
UPDATE 3
Cloning to /Users/dstein/Repositories/my-app
fails. Cloning to /Users/dstein/my-app
works. Cloning to /Users/dstein/Repositories/abc/my-app
works. Not sure what could be targeting that one random path to failure, esp given that renaming the folder of my-app
itself was working.