有没有人能够得到这个要求或调试NPM模块在浏览器中工作

Has anyone been able to get this require or debug NPM module to work in the browser?

本文关键字:NPM 调试 模块 工作 浏览器 没有人      更新时间:2023-09-26

有人能够让这个需要或调试的NPM模块在浏览器中工作吗?

根据截图&调试NPM模块页面上的指令,可以这样使用它。然而,尝试使用它会导致出现以下错误:

Uncaught ReferenceError: require is not defined

我该如何解决这个问题?我知道浏览NPM模块允许我们使用CCD_ 1方法&它需要从ES6->ES5中转。所以我试着通过安装所需的NPM模块来绕过传输要求。。。但这也不起作用。

问题是:有人能够让需求或调试模块在浏览器中工作吗?如果是这样的话,你是如何让它们发挥作用的?

这里有一个简单的例子。

helloworld.js

// create a logger with name `hello-world`
const debug = require('debug')('hello-world');
debug('hello world');

index.html

<!doctype html>
<html>
  <head>
    <script>
      // enable loggers with name matching `hello-world`
      localStorage.debug = 'hello-world'
    </script>
    <script src='bundle.js'></script>
  </head>
</html>

要生成bundle.js,可以使用Browserify:

$ browserify helloworld.js > bundle.js