Skip to content
New issue

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

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

Already on GitHub? # to your account

TypeError: window.require is not a function #2575

Open
2 of 13 tasks
cwu-ms opened this issue Dec 22, 2022 · 5 comments
Open
2 of 13 tasks

TypeError: window.require is not a function #2575

cwu-ms opened this issue Dec 22, 2022 · 5 comments

Comments

@cwu-ms
Copy link

cwu-ms commented Dec 22, 2022

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

Notoriously common issues

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(<HealthStatusAnchor healthStatus={health} resourceId={resourceId} isImpactedEnabled={isIREnabled}/> );
         |                         ^
      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.<anonymous> (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
  • 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

  • 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 ( )
@ljharb
Copy link
Member

ljharb commented Dec 22, 2022

To use any node module in a browser, it should be bundled by a working node module bundler. In node, require is always present in CJS modules. I'm really unsure where this error could be coming from, and I think you'll need to provide more info.

@cwu-ms
Copy link
Author

cwu-ms commented Dec 23, 2022

@ljharb What other info would be helpful?

@ljharb
Copy link
Member

ljharb commented Dec 23, 2022

@cwu-ms are you using a bundler? What test runner/framework are you using? Is this error occurring in a browser or in node? which node version?

@cwu-ms
Copy link
Author

cwu-ms commented Dec 23, 2022

We are using Jest, and the error is appearing in node when we run npm run test, for jest --config ./test-config/jest.config.js --verbose. As for a bundler, we are using webpack.

@ljharb
Copy link
Member

ljharb commented Dec 23, 2022

Presumably webpack isn’t involved for the jest tests, though - can you share your jest config?

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

No branches or pull requests

2 participants