Enzyme: Cannot find module 'react-test-renderer/package' from 'ReactSixteenAdapter.js'

Created on 13 Mar 2019  路  11Comments  路  Source: enzymejs/enzyme

Current behavior

Cannot find module 'react-test-renderer/package' from 'ReactSixteenAdapter.js'
Broke in https://github.com/airbnb/enzyme/commit/98154a945390014a9c97e3a4c6d83eac42f3d73f
Changing the import from:
import { version as testRendererVersion } from 'react-test-renderer/package';
to
import { version as testRendererVersion } from 'react-test-renderer';

Solves the issue for me.

Expected behavior

No error...

Your environment

API

  • [ ] shallow
  • [ ] mount
  • [ ] render

Version

| library | version
| ------------------- | -------
| enzyme | 3.9.0
| react | 16.8.4
| react-dom | 16.8.4
| react-test-renderer | 16.8.4
| adapter (below) |

Adapter

  • [x ] enzyme-adapter-react-16
  • [ ] enzyme-adapter-react-16.3
  • [ ] enzyme-adapter-react-16.2
  • [ ] enzyme-adapter-react-16.1
  • [ ] enzyme-adapter-react-15
  • [ ] enzyme-adapter-react-15.4
  • [ ] enzyme-adapter-react-14
  • [ ] enzyme-adapter-react-13
  • [ ] enzyme-adapter-react-helper
  • [ ] others ( )
package 16

Most helpful comment

Just freeze it to ~1.10.0 for now. No need to write "same here" 100500 times

All 11 comments

Was about to create the same issue xD

Same issue here

Same for me. It would be great to get a hotfix asap.

Thanks)

Just freeze it to ~1.10.0 for now. No need to write "same here" 100500 times

This shouldn鈥檛 break for anyone - node supports importing json files without an extension.

If it鈥檚 not working, then your environment is broken.

Adding "json" to jest.moduleFileExtensions in our package.json file works around this problem. Still, I consider it a bug in enzyme-adapter-react-16 to require this configuration.

Considering that's the default configuration of node itself, it's a bug in your jest configuration.

@srittau if you remove your fix to your jest config, and change the import in the adapter to have an explicit .json extension, does that fix the issue for you?

@ljharb It does.

I admit that it makes sense for enzyme to expect to be able to include things without extension, according to node's default configuration. I believe the root problem is that jest does not have an option to add to the default list of file extensions in package.json, just to replace it. But I think enzyme can help maintainers by changing the import of the json file (a not too common case) to include the suffix.

We now opted to remove jest.moduleFileExtensions, since all extensions required by us are now contained in jest's default configuration anyway.

Either way, I'll close this issue by explicitly adding the extension, since that seems to be the best compromise.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivanbtrujillo picture ivanbtrujillo  路  3Comments

dschinkel picture dschinkel  路  3Comments

blainekasten picture blainekasten  路  3Comments

nelsonchen90 picture nelsonchen90  路  3Comments

thurt picture thurt  路  3Comments