Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

.mjs files in node_modules break jest #287

Closed
mbrowne opened this issue Mar 27, 2018 · 3 comments
Closed

.mjs files in node_modules break jest #287

mbrowne opened this issue Mar 27, 2018 · 3 comments

Comments

@mbrowne
Copy link

mbrowne commented Mar 27, 2018

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

Yes

Environment

All environments

Steps to Reproduce

  1. yarn add graphql@0.13.2 @types/graphql

  2. Add the following code to App.tsx:

     import { graphql } from 'graphql'
     console.log(graphql)
    
  3. yarn test -t 'renders without crashing'

Expected Behavior

Test should pass

Actual Behavior

 FAIL  src/App.test.tsx
  ● Test suite failed to run

    /Users/mbrowne/_temp/test-app/node_modules/graphql/index.mjs:2
    export { graphql, graphqlSync } from './graphql';
    ^^^^^^

    SyntaxError: Unexpected token export

Solution

This is a known bug in create-react-app. The fix should be simple: simply merge this PR into this repo (it was already merged into the official create-react-app).

@gaearon
Copy link
Contributor

gaearon commented Apr 3, 2018

If your project is built with Create React App and not ejected, react-scripts@1.1.2 should fix this.
Here is how to upgrade:

https://github.com/facebook/create-react-app/releases/tag/v1.1.2

Otherwise you can apply a similar fix yourself in your project config. Cheers!

@mbrowne
Copy link
Author

mbrowne commented Apr 11, 2018

@gaearon this still needs to be fixed in react-scripts-ts. It doesn't make sense to use the official version of react-scripts as all the important functionality of this repo is provided by react-scripts-ts. But yes, you can alternatively eject and then apply that fix manually.

@mbrowne
Copy link
Author

mbrowne commented Apr 11, 2018

It looks like currently, .mjs files are actually included twice in the array in react-scripts-ts (at the beginning and at the end):
https://github.com/wmonk/create-react-app-typescript/blob/master/packages/react-scripts/scripts/utils/createJestConfig.js#L50

Maybe the result of a bad merge?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants