从同级文件夹导入打字稿 - 找不到模块

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

从其他文件夹导入模块会导致打字稿错误。 我有一个具有类似结构的项目:

 - src
    - tsconfig.json
    - types
      - math.types.ts
    - utils
      - addNumbers.ts
 - playwright
    - tsconfig.json
    - dashboard.page.ts
  • src
    文件夹中有typescript中的react应用程序和一些可以在playwright中使用的实用程序
  • playwright
    有应用程序的 e2e 测试

现在,当我从

src
文件夹(例如
addNumbers
)导入
playwright/dashboard.page.ts
文件中的内容,然后运行命令(在 playwright 文件夹中)时:

tsc -p tsconfig.json

我得到:


../src/utils/addNumbers.ts:4:45 - error TS2307: Cannot find module 'types/math.types' or its corresponding type declarations.

import { SomeNumberType } from 'types/math.types';

当我在

src
文件夹中运行 tsc 时,导入工作正常,当我在
playwright
文件夹中启动 tsc 时,一切都损坏了。

我错过了什么吗?

typescript import module bundle
1个回答
0
投票

在 React 应用程序中,您无法访问 src 之外的文件夹,您是否尝试重用某些模块?

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