naviapps / create-nw-react-app

Create NW.js React apps with no build configuration.
MIT License
144 stars 14 forks source link

Uncaught ReferenceError: require is not defined #4

Closed mparker11 closed 6 years ago

mparker11 commented 6 years ago

I'm pretty fresh on this project and I've barely added anything, but I'm getting Uncaught ReferenceError: require is not defined when doing npm start. I've tracked this down to the webpack-dev-server package, line 1. With this problem, I am not able to view my project in my regular browser using localhost:3000. Does anyone know how this can be fixed without ejecting?

naviapis commented 6 years ago

I need to update the README, but I no longer support checking on the browser. This is because you can not use the NW.js API (nw.) or the Chrome Extension API (chrome.) on the browser. Therefore, development should be done in the window opened with npm start.

Thanks.

mparker11 commented 6 years ago

@naviapis Thank you for that! I just hit another config question: I'm trying to use React Router but I can't seem to get the starting route to simply be / (which will be my home page). I found the line in package.json where the starting url is index.html but when I changed it to /, I got this Chrome error:

The webpage at chrome-extension://flimcfogogbacdgkdhpbncbjhmdfhnlm/ might be temporarily down or it may have moved permanently to a new web address.

How can I mimic the beginning route as if I were starting at localhost:3000/?

mparker11 commented 6 years ago

I figured out to put /index.html in my route's config. Pretty simple fix smh. However, I'm still curious about the architecture where there must be /index.html attached the to route. Any insight on that?

naviapis commented 6 years ago

The main setting of package.json is the endpoint file path used in NW.js.

There is a related example project. Create NW.js React App ejected + React router + Redux + Redux saga https://github.com/naviapps/nw-react-boilerplate Routes https://github.com/naviapps/nw-react-boilerplate/blob/master/src/routes.js

It is not necessary to eject.

mparker11 commented 6 years ago

Ok, great. That's what I ended up figuring out. Thanks so much for the responses!

naviapis commented 6 years ago

The default URL of NW.js seems to be chrome-extension: //********/index.html. NW.js probably gets the main in package.json as the file path. I think this is similar to the URL when the local file was opened in the browser. file:///Users/Guest/my-app/index.html However, it should be possible to display even here. file:///Users/Guest/my-app/

naviapis commented 6 years ago

Close comment. Thanks.