Client on node: Uncaught ReferenceError: require is not defined

前端 未结 8 1476
遥遥无期
遥遥无期 2020-11-21 07:20

So, I am writing an application with the node/express + jade combo.

I have client.js, which is loaded on the client. In that file I have code that calls

相关标签:
8条回答
  • 2020-11-21 08:19

    Even using this won't work , I think the best solution is browserify:

    module.exports = {
      func1: function () {
       console.log("I am function 1");
      },
      func2: function () {
        console.log("I am function 2");
      }
    };
    
    -getFunc1.js-
    var common = require('./common');
    common.func1();
    
    0 讨论(0)
  • 2020-11-21 08:20

    This Worked For Me

    1. Save this file https://requirejs.org/docs/release/2.3.5/minified/require.js. It is the file for RequestJS which is what we will use.
    2. Load into your HTML like this
      <script data-main="your-script.js" src="require.js"></script>

    Note!
    use require(['moudle-name']) in your-script.js
    not require('moudle-name')
    use const {ipcRenderer} = require(['electron'])
    not const {ipcRenderer} = require('electron')

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