Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Can't resolve 'http' error when using on React app #534

@cardil

Description

@cardil

Describe the Bug
I'm trying to use CE javascript SDK in a React app. I have the following err:

ERROR in ./node_modules/cloudevents/dist/transport/http/index.js 16:31-46

Module not found: Error: Can't resolve 'http' in '/home/ksuszyns/git/openshift-knative-showcase/frontend/node_modules/cloudevents/dist/transport/http'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
	- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "http": false }

That error is thrown just after trying to create the CE:

const ce = new CloudEvent({})

I just wanted to parse incoming Server Sent Events data that is in structured-mode CE.

Steps to Reproduce

  1. Create React app with: npx create-react-app frontend --template typescript
  2. Install CE: npm i --save cloudevents
  3. Import CE and attempt to create basic object:
    import { CloudEvent } from 'cloudevents'
    
    const ce = new CloudEvent({})

You can also see this error on this commit: cardil/openshift-knative-showcase@cc8ffe2

Expected Behavior

I just want to create basic CE objects, in React app. And parse them from the JSON text, in the near future. No errors should be thrown.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions