Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined error at runtime while using react-redux along with ASP.NET Core

I'm using react/redux in an ASP.NET Core application and everything goes smooth if i don't include redux but after adding redux and change current components to connect to the store, i get following errors in the browser (after publish the website t wwwroot folder):

ReferenceError: Provider is not defined

or

ReferenceError: connect is not defined

...

Note that in my wwwwroot folder i have added the react-redux.js file which exists in dist folder of react-redux module in node-modules.

---node_modules\react-redux\dist\react-redux.js----

in the following i put the code of one of my containers which shows me error at runtime in the browser:

declare var { connect }: typeof import("react-redux");

import { addTodo } from '../redux/actions/todo-actions.js';
import AddTodoForm from '../components/AddTodoForm.js';

const mapDispatchToProps = {
    handleSubmit: addTodo
};

export default connect<any, any, any>(null, mapDispatchToProps)(AddTodoForm)

To me it sounds like, the reaxt-redux.js that i have added to the wwwroot folder isn't exporting its interfaces (specifically connect interface) into the window properly!

Consider that i'm not having node-modules and npm on my servers so i prefer to reference the react,redux and react-redux javascript files manually in my pages.

Can you please let me know what i'm doing wrong?

Thanks in advance

like image 811
Mike Avatar asked Sep 05 '26 15:09

Mike


1 Answers

I found the issue. As i was using Webpack, as i had more than one component on the page, the redux store was bundled and added more than once. Needed to change the store.tsx to prevent it.

like image 98
Mike Avatar answered Sep 07 '26 05:09

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!