【问题标题】:browserify not working, Uncaught ReferenceError: require is not definedbrowserify 不工作,Uncaught ReferenceError: require is not defined
【发布时间】:2020-12-26 01:10:24
【问题描述】:

我是 node.js 的新手,我一直在尝试在我的 chrome 扩展中使用一个使用 require 的函数 - 但是,即使在之后 安装浏览器, 将 content.js 中的模块捆绑到 bundle.js 中, 并尝试使用

browserify content.js --standalone Bundle > bundle.js

我还在继续

Uncaught ReferenceError: require is not defined

任何帮助将不胜感激,如果这是一个愚蠢的问题,我真的很抱歉哈哈哈

【问题讨论】:

    标签: javascript node.js browserify require


    【解决方案1】:

    为了让它对我有用,我添加了...

    <script type="text/javascript" src="bundle.js"></script>
    

    在我的 html 页面中结束正文调用之前。所以你的 html 文件应该看起来像......

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset = "utf-8"/>
            <title> clickerance </title>
            <link type="text/css" rel="stylesheet" href="style.css"/>
            <script src="bundle.js"></script>
        </head>
        <body>
          <div class="Title"></div>
            <h1> Clickerance </h1>
     
            Dairy  : <input type="checkbox" id="Dairy"><br>
            Meat   : <input type="checkbox" id="Meat"><br>
            Corn   : <input type="checkbox" id="Corn"><br>
            Gluten : <input type="checkbox" id="Gluten"><br>
     
            <p>Which ones you can't eat?</p>
     
            <input id="Submit" type="submit" value="Submit">
        <script type="text/javascript" src="bundle.js"></script>
        </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 2013-08-14
      • 2017-02-25
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 2017-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多