enzymejs / enzymejs/enzyme

TypeError: window.require is not a function

Open
#2,575 5 comments 0 reactions 0 assignees View on GitHub
Need More Information
Dominant language
JavaScript
Stars
19.8k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

Thanks for reporting an issue to us! We're glad you are using and invested in Enzyme.
Before submitting, please read over our commonly reported issues to prevent duplicates!

### All common issues

* [common issues](../blob/master/docs/common-issues.md)

### Notoriously common issues

* [Webpack build issues](../blob/master/docs/common-issues.md#webpack-build-issues)
* [Cannot find module 'react-dom/lib/ReactTestUtils'](../blob/master/docs/common-issues.md#error-cannot-find-module-react-domlibreacttestutils)
* [Query Selector fails](../blob/master/docs/common-issues.md#query-selector-fails)
* [Testing third party libraries](../blob/master/docs/common-issues.md#testing-third-party-libraries)

If you haven't found any duplicated issues, please report it with your environment!

### Current behavior

When testing my project, I get this error with the mount() function:
image
```
TypeError: window.require is not a function

57 | };
58 |
> 59 | const wrapper = mount( );
| ^
60 |
61 | wrapper.find('button').simulate('click');
62 | expect(openBladeSpy).toHaveBeenCalledTimes(1);

at Object.getErrorBoundary (node_modules/azureportal-reactview/src/internal/ErrorBoundary.tsx:206:33)
at _FrameworkIcon (node_modules/azureportal-reactview/src/FrameworkIcon.tsx:51:27)
at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:14803:18)
at mountIndeterminateComponent (node_modules/react-dom/cjs/react-dom.development.js:17482:13)
at beginWork (node_modules/react-dom/cjs/react-dom.development.js:18596:16)
at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:188:14)
at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:237:16)
at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:292:31)
at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:23203:7)
at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:22157:12)
at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:22130:22)
at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:21756:9)
at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:21188:7)
at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:24373:3)
at node_modules/react-dom/cjs/react-dom.development.js:24758:7
at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:21903:12)
at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:24757:5)
at Object.render (node_modules/react-dom/cjs/react-dom.development.js:24840:10)
at fn (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:488:26)
at node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:405:37
at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:21856:12)
at Object.act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:929:14)
at wrapAct (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:405:13)
at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:474:16)
at new ReactWrapper (node_modules/enzyme/src/ReactWrapper.js:115:16)
at Object.mount (node_modules/enzyme/src/mount.js:10:10)
at Object. (components/common/__tests__/HealthStatusAnchor.spec.tsx:59:25)
```

### Expected behavior
This test was running before, but after running `yarn install`, some of our other dependencies were updated and now the mount() function is throwing errors. We're not sure why this might be happening, since the relation between these updates and the new error is not clear. Does anyone know why this is happening?

### Your environment

#### API

- [ ] shallow
- [x] mount
- [ ] render

#### Version

| library | version
| ------------------- | -------
| enzyme | 3.11.0
| react | 16.14.0
| react-dom | 16.14.0
| react-test-renderer | 16.14.0
| 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 ( )

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.