Skip to content

Unexpected token import when running Non-Related React tests #2524

Closed
@dschinkel

Description

@dschinkel

Normally in any react project that is not a create-react-app app, you'd simply add the "ES2015" preset to get rid of this but for some reason, and knowing create-react-app is its own "animal" with how it works with babel under the hood because "everything is automated for you" which leaves me a black hole to deal with.

So that's why I'm posting this here. I have been able to run my react mocha tests just fine after adding the react-app preset in my package.json a long time ago. But I can't run my new develop mocha tests, for some reason I keep getting this error still:

above is an error during my travis build when it tries to run yarn run test.
This is output from Travis, not my local running of yarn run test.

My setup

I've got deployment code using ES6 imports in src/deploy/ and I have mocha unit tests exercising that code The deploy code is making various calls to aws S3 using their cli API to make calls. Travis looks at my travis.yml, and runs these scripts for this apps build process.

.babelrc - I added this because adding the react preset solved an error where jsx was not parsing in my react for some reason all of a sudden (I don't know why it decided to start to complain) and kept getting the error unexpected token on <MemoryRouter in app.spec.js in my test. Adding the react preset solved that
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"]
}

Adding the "es2015" allowed me to rid the error Unexpected token import on my deployment tests when I run them locally...after adding the .babelrc to solve my other jsx parse error.

Adding the transform-object-rest-spread was necessary or else my deploy code wasn't able to use the rest-spread

So I can't fix this error above. If I take out .babelrc or take out "es2015" my tests no longer run locally. If I keep "es2015" + "react" presets, the tests run locally, but fail on travis, the error you see above in the screenshot.

I do not know why all of a sudden this test started to complain with the jsx parsing either:

I also recently upgraded to Node 8 and npm 5.0.3 to take advantage of some of the new utilities.

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions