Need help to run in vsCode a React-Redux app from lesson: Connect the Redux Store to a UI

Connect the Redux Store to a UI

Any help is appreciated.

Things I have tried:
1- const { createStore } = require(‘redux’);

2- import { createStore } from ‘redux’; with a package.json file including: “type”: “module”

3- using the .mjs extension (store.mjs)

In each case respectively, I get these errors:

1- (require)
WITHOUT script tags:
Uncaught SyntaxError: Cannot use import statement outside a module
:5501/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)

WITH script tags:
react-16-redux-4-bundle.min.js:121 You are currently using minified code outside of NODE_ENV === “production”. This means that you are running a slower development build of Redux. You can use loose-envify (GitHub - zertosh/loose-envify: Like envify but much faster) for browserify or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) to ensure you have the correct code for your production build.

2- (import) Uncaught SyntaxError: Cannot use import statement outside a module
:3000/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)

3- (mjs) Uncaught SyntaxError: Cannot use import statement outside a module
:3000/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)

I always use npx create-react-app my-app to create the React app and never had difficulties using the import statement (import { createStore } from 'redux') with react. How did you create the React app?

1 Like

Thanks for the reply. The create-react-app should work. It has been almost 5 months since I completed the React courses and I just came back to resume the Redux. So I had forgotten about create-react-app. I successfully created the react app, and the default app ran perfectly.

Everything I tried to do to replace the default app.js with store.js code has failed. But, I think I will be able to get it done since you put me on the right track.

Again thanks for your help.

1 Like

Sadly using create-react-app is overkill for what I am trying to do. It creates thousands of files. I need a quick way to duplicate a lesson in vsCode.

This is not a problem with when the lesson is straight javascript and/or html. The lessons, as you know, are usually short one or two code files. I already have nearly a hundred or more of the lessons nicely organized under my Codecademy folder.

I can’t help you with your problem then, I’m afraid. You’ll need some kind of setup. And a redux store would be an overkill for a tiny project anyway. So I’d go with the create react app.

Of course Redux would be overkill for a small app. I am not working with a real app. It is one of the Codecademy lessons on how to use Redux. Those are small apps.