Client on node: Uncaught ReferenceError: require is not defined

前端 未结 8 1479
遥遥无期
遥遥无期 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:09

    ES6: In html include main js file using attribute type="module" (browser support):

    
    

    And in script.js file include another file like that:

    import { hello } from './module.js';
    ...
    // alert(hello());
    

    Inside included file (module.js) you must export function/class that you will import

    export function hello() {
        return "Hello World";
    }
    

    Working example here. More info here

提交回复
热议问题