Uncaught ReferenceError: process is not defined

前端 未结 3 2004
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 23:06

I am using node.js to create a web application. When I run the application (either by opening index.html on the browser or using the command \"npm start\" on the terminal) I

相关标签:
3条回答
  • 2021-01-07 23:44

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

    The require in html was reached from a < script> and was undefined, like

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

    I changed it to:

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

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

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

    I hope it helped.

    0 讨论(0)
  • 2021-01-07 23:56

    Node.js code must be run by the node process, not the browser (the code must run in 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 "http://localhost:8080", for example. You must have a file server.js (or whatever) with the server code you want (in this case, creating a web server in port 8080).

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

    0 讨论(0)
  • 2021-01-07 23:59

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

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

    0 讨论(0)
提交回复
热议问题