Typescript路径未解析

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

我一直试图在我的项目中解决路径问题,但是我找不到使它起作用的方法。我的项目是使用电子webpack的电子项目。

我的文件夹结构如下:

enter image description here

我想为./src/main和./src/renderer注册@main和@render的路径我的tsconfig.json目前看起来像这样:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "esnext",
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noImplicitReturns": true,
    "inlineSources": true,
    "inlineSourceMap": true,
    "experimentalDecorators": true,
    "newLine": "lf",
    "noEmitOnError": true,
    "jsx": "react",
    "esModuleInterop": true,
    "lib": ["es2015", "es2016", "DOM"],
    "typeRoots" : ["./node_modules/@types"], 
    "baseUrl": "./src",
    "paths": {
      "@main/*" : ["main/*"],
      "@render/*" : ["renderer/*"]
    },
   "allowSyntheticDefaultImports": true,
   "resolveJsonModule": true
  }
}

但是VS Code警告我,它找不到模块。该行如下所示:

import { Api } from '@render/api'

我该如何解决?

typescript webpack
1个回答
0
投票

您需要重新启动IDE和TS服务。更改配置时,必须重新启动TS以检测新更改。

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