简体   繁体   English

我不知道为什么我的 npm 没有响应 var uc = require('upper-case');

[英]I don't know why my npm have no respond that is var uc = require('upper-case');

i just following the w3school npm tutorial, but it no respond.我只是按照 w3school npm 教程进行操作,但没有响应。

i am using macbook pro 2019, and using Vs code to program it.我正在使用 macbook pro 2019,并使用 Vs 代码对其进行编程。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p id=uc></p>
        <script>
            var uc = require('upper-case');
            document.getElementById('uc').innerHTML = uc("asdjkad");
        </script>
</body>
</html>

xxx and yyy is a filter of me and my computer name xxx 和 yyy 是我和我的计算机名称的过滤器

(base) xxx:~ yyy$ npm ls -g
/Users/yyy/.npm-global/lib
├─┬ increase-memory-limit@1.0.7
│ └─┬ glob@7.1.4
│   ├── fs.realpath@1.0.0
│   ├─┬ inflight@1.0.6
│   │ ├── once@1.4.0 deduped
│   │ └── wrappy@1.0.2
│   ├── inherits@2.0.4
│   ├─┬ minimatch@3.0.4
│   │ └─┬ brace-expansion@1.1.11
│   │   ├── balanced-match@1.0.0
│   │   └── concat-map@0.0.1
│   ├─┬ once@1.4.0
│   │ └── wrappy@1.0.2 deduped
│   └── path-is-absolute@1.0.1
├── jquery@3.4.1
└── upper-case@1.1.3

i expect the html/javascript can run the upper-case node我希望 html/javascript 可以运行大写节点

require isn't a built-in part of JavaScript or the browser environment. require不是 JavaScript 或浏览器环境的内置部分。 It's a built-in part of the Node.js (non-browser) environment, and a function provided by various libraries and bundlers (such as Webpack and Browserify).它是 Node.js(非浏览器)环境的内置部分,也是各种库和捆绑器(例如 Webpack 和 Browserify)提供的功能。

If you want to use an npm module in browser-hosted code, you have to either:如果要在浏览器托管的代码中使用npm模块,则必须:

  1. Include it via script tag, provided it doesn't rely on any other modules (unlikely), or通过script标签包含它,前提是它不依赖任何其他模块(不太可能),或者

  2. Use a bundler that understands require syntax and can bundle up the module code into a browser-compatible script.使用理解require语法并且可以将模块代码捆绑到浏览器兼容脚本中的捆绑器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM