小编Ali*_*ina的帖子

Eslint + typescript 路径别名 - 无法解析模块的路径

我为路径添加打字稿配置:

{
 //.....

 "moduleResolution": "node",
{
  "baseUrl": "app",
  "paths": {
  "@app/*": ["*"],
  "@folder/*": ["folder/*"],

  //Other paths
},
Run Code Online (Sandbox Code Playgroud)

}

为 webpack 添加配置:

  resolve: {
  extensions: [".tsx", ".ts", ".js", ".jsx", ".css", ".json"],
  alias: {
    "@app":path.resolve(__dirname + "../", "app"),
    "@services":path.resolve(__dirname + "../app", "folder")
  },
  modules: [
    "node_modules", path.resolve(process.cwd(), "app")
  ],
  plugins: [
    new TsConfigPathsPlugin({
      configFile: "../tsconfig.json"
    }),
  ],
},
Run Code Online (Sandbox Code Playgroud)

这是我的 .eslint 文件:

"settings": {
"import/resolver": {
  "node": {
    "paths": [
      "app"
    ],
    "extensions": [
      ".ts",
      ".tsx",
      ".jest.tsx",
      ".d.ts"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

之后我尝试导入这样的东西:

import …
Run Code Online (Sandbox Code Playgroud)

reactjs eslint tsconfig react-tsx typescript-eslint

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

eslint ×1

react-tsx ×1

reactjs ×1

tsconfig ×1

typescript-eslint ×1