Uncaught ReferenceError: process not defined

I am using node.js to build a web application. When I start the application (by opening index.html in a browser or using the "npm start" command in a terminal) I get two errors:

Uncaught ReferenceError: process not defined

Uncaught ReferenceError: Requirement not defined

I resolved the "Required is not defined" error by specifically including in my index.html header tag a link to this script where the require function is defined. However, I cannot find something similar for the process function.

My question is twofold:

  1. Why do built-in node.js modules need to be overridden? Why are they not recognized as they are, that is, "built-in modules"? Doesn't the term "inline module" mean that the module doesn't need to be redefined externally / second-hand?

  2. Is there a way to solve this problem? My scenario is very simple, I'm just trying to use a basic node.js function, so I can't figure out what mistakes I might have made.

If anyone came across this problem and found a way around it or for any reason, you would be of great help.

+8


source to share


3 answers


Node.js must be executed by the node process, not the browser (the code must be executed on the server).

To run the code, you must run the command:

node server.js

      



And then you can access your server from a browser by typing for example http: // localhost: 8080 ". You should have a server.js file (or whatever) with the required server code (in this case creating a web -server on port 8080).

You can follow this simple example using express as a http server module: http://expressjs.com/starter/hello-world.html

+3


source


I had the same problem which I solved by going into my .eslintrc.js file to configure my globals, adding require and process to the globals variable and setting the appropriate value to "writable". Hope this works for you.



this link really helped https://eslint.org/docs/user-guide/configuring#specifying-globals

+2


source


I had the same problem when trying to make this js node app: https://www.youtube.com/watch?v=mr9Mtm_TRpw

The html request was obtained from & lt; script> and was undefined like

<script> require('./renderer.js');</script>

      

I changed it to:

<script src="./renderer.js"></script>

      

The process in the html script was also undefined. I have included webPreferences: nodeIntegration in the js file:

win = new BrowserWindow({
    width: 800, 
    height:600, 
    icon: __dirname+'/img/sysinfo.png', 
    webPreferences: {
        nodeIntegration: true
    }
});

      

I hope this helped.

+1


source







All Articles