简体   繁体   English

如何在 DENO 中导出 deps?

[英]How to export deps in DENO?

I would like to know how I can export npm modules as express For example, I have the following import, it works fine and the linter does not show any errors:我想知道如何将 npm 模块导出为 express 例如,我有以下导入,它工作正常并且 linter 没有显示任何错误:

import express, { Request, Response } from 'npm:express';

however when taking it to my deps.ts I get the following error:然而,当把它带到我的 deps.ts 时,我收到以下错误:

export express, { Request, Response } from 'npm:express';

Error:错误:

';' expected.

try to separate it but it gives another error:尝试将其分开,但它给出了另一个错误:

export express from 'npm:express'; export { Request, Response } from 'npm:express';

Error:错误:

Unexpected keyword or identifier

Then try the following:然后尝试以下操作:

import express from 'npm:express'; export { Request, Response } from 'npm:express'; export { express };

but i get the following error:但我收到以下错误:

Uncaught SyntaxError: The requested module 'npm:express' does not provide an export named 'Request' export { Request, Response } from 'npm:express';

and I don't know how to solve it, I hope you can help me, I don't want to use a default import in my app.ts file, I hope you can help me我不知道如何解决,希望你能帮助我,我不想在我的 app.ts 文件中使用默认导入,希望你能帮助我

The default export from the express package is a function , but Request and Response are type interfaces . express package 的默认导出是function ,但RequestResponse是类型接口

When exporting types, you should use the type modifier , like this:导出类型时,您应该使用type修饰符,如下所示:

./deps.ts : ./deps.ts

export { default as express, type Request, type Response } from "npm:express";

Then, those exported dependencies can be imported into another module like this:然后,可以将这些导出的依赖项导入到另一个模块中,如下所示:

./mod.ts : ./mod.ts

import { express, type Request, type Response } from "./deps.ts";

console.log("typeof express:", typeof express); // typeof express: function

You can then run the mod.ts module in the terminal and see this output:然后您可以在终端中运行mod.ts模块并看到这个 output:

% deno --version
deno 1.29.4 (release, x86_64-apple-darwin)
v8 10.9.194.5
typescript 4.9.4

% deno run --allow-env --allow-read mod.ts
typeof express: function

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

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