首页 > 解决方案 > 无法在节点项目上导入 *d.ts

问题描述

我有以下代码结构:

src
├── config
│   └── index.ts
├── db
│   ├── index.ts
│   └── Schema.json
├── graphql
│   ├── resolvers.ts
│   └── schema.graphql
├── index.ts
└── models
    ├── graphql.d.ts
    └── index.d.ts

问题是当尝试使用以下代码在 resolvers.ts 上导入模式时会发生什么:

import {IPhoto} from '../models'

我得到以下选项:

错误:找不到模块“../models”

tsconfig.json 如下:

{
  "compilerOptions": {
    "outDir": "./build",
    "allowJs": true,
    "target": "es2019",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*"]
    }
  },
"include": ["src/**/*", "src/scripts", "package.json", "types/**/*", "src/scripts/**/*"],
  "exclude": [
    ".cache",
    "acceptance-tests",
    "build",
    "coverage",
    "jest.config.js",
    "jest",
    "node_modules"
  ]
}

为了启动它,我使用以下脚本:

"dev": "env-cmd tsnd --respawn src/index.ts",

我该如何解决这个问题?

谢谢

标签: node.jstypescriptgraphql

解决方案


推荐阅读