Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel plugin missing after upgrading to v3 #1176

Closed
Fatxx opened this issue Sep 27, 2017 · 10 comments
Closed

Babel plugin missing after upgrading to v3 #1176

Fatxx opened this issue Sep 27, 2017 · 10 comments

Comments

@Fatxx
Copy link

Fatxx commented Sep 27, 2017

While executing tests using jest I'm facing the following error after upgrade to v3:
ReferenceError: Unknown plugin "transform-replace-object-assign" specified in "${pathToProject}/node_modules/enzyme/.babelrc" at 0, attempted to resolve relative to "${pathToProject}/node_modules/enzyme"

package.json:

"scripts": {
...
"test": "node node_modules/jest/bin/jest.js --setupTestFrameworkScriptFile=./App/__tests__/setupTests.js --watch",
...
},
"dependencies": {
     "react": "^16.0.0",
    "react-native": "^0.47.2",
},
"devDependecies": {
    "babel-preset-react-native": "^2.1.0",
    "enzyme": "^3.0.0",
    "enzyme-adapter-react-16": "^1.0.0",
    "jest": "^20.0.4",
}

setupTests.js:

import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() })

Anyone facing this or any clue how to solve it?

@lelandrichardson
Copy link
Collaborator

sigh. this is from react native's terrible behavior of transpiling node_modules. This is probably indicative of us now not npm ignoring our .babelrc file, whereas we used to before.

In the short term, you might be able to configure jest to ignore certain modules... i don't remember how to do that but some googling might uncover something. Or you can just manually delete the babelrc in enzyme and enzyme-adapter-react-16 node_modules folders.

@Fatxx
Copy link
Author

Fatxx commented Sep 27, 2017

@lelandrichardson thanks for your fast response.

You mean this:

"jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|react-navigation|core-js)/"
    ]
  }

Probably? Uhm manually deleting doesn't seem an option for teams I believe.

@ljharb
Copy link
Member

ljharb commented Sep 27, 2017

@Fatxx manually deleting is fine if you do it as a postinstall script; if RNP still is broken and babel-transpiles node_modules, then you'd want to delete every .babelrc inside it.

@Fatxx
Copy link
Author

Fatxx commented Sep 27, 2017

Uhm I see, as @skovhus pointed out here: #928 (comment)

@lelandrichardson
Copy link
Collaborator

@Fatxx for reference, airbnb does the following in our react native code base in a postinstall script:

(find node_modules -type f -name .babelrc | grep -v /react-native/ | xargs rm) || true

super hacky, but the bug lies with react native, not with enzyme... although I will consider adding the babelrcs to the npmignore in the next release anyway in order to make consuming enzyme easier for people.

@skovhus
Copy link

skovhus commented Sep 27, 2017

Yeah adding the following to your package.json does the trick (for now)...

"postinstall": "rm -f node_modules/enzyme/.babelrc"

But seems this might have been fixed in newer version of react-native... Haven't tested this.

@lelandrichardson
Copy link
Collaborator

going to place the v3 bugs label back on this issue. I don't think this was an expected difference between v2 and v3, though calling it a "bug" is a bit of a stretch, it's still something i'd like to fix on our end so this label will remind me.

@Fatxx
Copy link
Author

Fatxx commented Sep 27, 2017

@lelandrichardson that script worked! @skovhus. Thank you both 👍

@asBrettisay
Copy link

Having this issue also using karma testrunner, and the script mentioned above does not work.

@lelandrichardson
Copy link
Collaborator

This is hopefully fixed in enzyme-adapter-react-{version}@1.0.1 and enzyme@3.1.0. Please upgrade and let us know if it does not fix your issue. Thanks!

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

No branches or pull requests

5 participants