简体   繁体   English

Nodejs要求()(require())导入

[英]Nodejs require()(require()) to import

I have been developing an application using Typescript that gets compiled into node code. 我一直在使用Typescript开发一个应用程序,它被编译成节点代码。 As such I prefer using import statements to require . 因此,我更喜欢使用import语句来require

I have been attempting to use Lodash with Lodash-Deep, with their official documentation stating that usage should be: const _ = require("deepdash")(require("lodash")); 我一直试图将Lodash与Lodash-Deep一起使用,他们的官方文档说明用法应该是: const _ = require("deepdash")(require("lodash"));

I wish to convert this into an import statement but have not seen anything like this before and can't find any information in Node docs that explain using require in this fashion. 我希望将其转换为import语句,但之前没有看到类似的内容,并且无法在Node文档中找到以这种方式解释使用require的任何信息。

Would anyone know how to do this or can point me towards the relevant resources so that my code can stay consistent. 有谁知道如何做到这一点或可以指向我相关的资源,以便我的代码可以保持一致。

The imported deepdash is a function, and it's need to be called with lodash object as the parameter. 导入的deepdash是一个函数,需要使用lodash对象作为参数调用它。

import lodash from "lodash"
import deepdash from "deepdash"

const _ = deepdash(lodash)

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

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