【问题标题】:Absolute import is not working with fastify-autoload绝对导入不适用于 fastify-autoload
【发布时间】:2023-01-30 14:51:01
【问题描述】:

我正在使用 typescript 构建 fastify 应用程序,但在使用绝对导入时遇到问题。

{
  "extends": "fastify-tsconfig",
  "compilerOptions": {
    "outDir": "dist",
    "sourceMap": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "baseUrl": "src",
    "emitDecoratorMetadata": true
  },
  "include": ["src/**/*.ts", "src"]
}

这是我的 tsconfig.json 文件。

import { User } from "entity/User";
import { FastifyPluginAsync } from "fastify";

const example: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
  fastify.get("/", async function (request, reply) {
    const users = await fastify.db.manager.find(User);
    return users;
  });
};

export default example;

这是我使用绝对导入的部分。

Visual Studio 代码不会显示错误,但是当我运行该应用程序时,会出现 MODULE_NOT_FOUND 错误。

我想这是因为 fastify-autoload 插件。 当然,我可以改用相对路径导入,但这会使代码混乱且难以阅读,所以我希望我能解决这个问题。

如果有人对此有经验,请帮助我。

【问题讨论】:

  • 您能否与我们分享您运行自动加载的脚本?

标签: node.js typescript absolute-path fastify


【解决方案1】:

@Meerkat 嗨这里有什么解决方案吗?

【讨论】:

  • 这篇文章看起来不像是试图回答这个问题。这里的每个帖子都应该是一个明确的尝试回答这个问题;如果你有批评或需要澄清问题或其他答案,你可以直接在它下面post a comment(就像这个)。请删除此答案并创建评论或新问题。见:Ask questions, get answers, no distractions
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-08
  • 1970-01-01
  • 2011-07-12
  • 1970-01-01
  • 2016-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多