gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:25:18 25 4
gpt4 key购买 nike

我为路径添加了 typescript 配置:

{
//.....

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

//Other paths
},

为 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"
}),
],
},

这是我的 .eslint 文件:

"settings": {
"import/resolver": {
"node": {
"paths": [
"app"
],
"extensions": [
".ts",
".tsx",
".jest.tsx",
".d.ts"
]
}
}

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

import {component} from "@folder/component";

一切都已组装,编译器不会产生错误但是我在 eslint 中遇到错误:

ESLint: Unable to resolve path to module '@folder/component'.(import/no-unresolved)

第三天我一直在努力解决这个问题客户不想安装额外的插件非常感谢您的帮助!

最佳答案

node 解析器不理解 TypeScript paths。所以它专门寻找一个名为 @folder/component 的节点模块 - 它不会存在。

您可以为插件使用 typescript 解析器: https://www.npmjs.com/package/eslint-import-resolver-typescript

关于reactjs - Eslint + typescript 路径别名 - 无法解析模块路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70306158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com