运行 tsc 时,TypeScript 出现错误 TS2307 找不到模块“src/”

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

我正在尝试为我的 React Native 项目中的包配置 tsconfig.json 以添加模块解析并使代码更清晰,而不是

所以文件夹结构是这样的:

root
--src
--packages
---src
----components
----constants
---tsconfig.json

import { LABELS } from "../../../constants";

我可以写

import { LABELS } from "src/constants"; or import { LABELS } from "@app-content/constants";

这是我的 tsconfig.json

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@app-content/*": ["./src/*"]
        }
    },
    "include": ["__tests__/**/*", "src/**/*", "typings/*"]
}

如果我写“src/”或“@app-content/”,该分辨率在 vs-code 上可以正常工作,它会显示正确的文件夹,并且当时没有错误,应用程序也运行成功,但是当我运行命令

tsc
它给出错误

error TS2307: Cannot find module 'src/constants' or its corresponding type declarations.
javascript reactjs typescript react-native tsconfig
1个回答
0
投票

我想我以前也遇到过这个问题,你检查过运行编译器的目录吗?

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