我似乎无法使npm模块“大写”正常工作

问题描述 投票:0回答:3

我如下安装了npm模块upper-case

npm install upper-case

此后,我在节点中执行了以下代码。

let http = require('http');
let uc = require('upper-case');
http.createServer( (req, res) => {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.write(uc("Hello World!"));
  res.end();
}).listen(8080);

但是,我无法正常工作。我得到以下回应。

TypeError: uc is not a function
    at Server.http.createServer (/.../foo.js:34:13)
    at Server.emit (events.js:189:13)
    at parserOnIncoming (_http_server.js:676:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)

为什么?这是怎么回事!?

node.js npm uppercase
3个回答
0
投票

您这样导入吗?>

import { upperCase } from "upper-case";

并尝试?

此包裹出口

/**
 * Upper case as a function.
 */
export function upperCase(str: string) {
  return str.toUpperCase();
}

所以您不能导入自己的名称uc

按仓库中的描述使用。


0
投票

ECMAScript 6:toUpperCase()


0
投票

真的很奇怪...但是以下内容由于某种原因似乎有效。我在原始npm模块文档中的任何地方都找不到。谁能解释为什么这样起作用?

© www.soinside.com 2019 - 2024. All rights reserved.