英文:
How to set root of project for ESLint?
问题
为了澄清,我的项目是使用Next.js和Typescript构建的。我一直以这种方式导入我的函数:import Component from "/components/Component/Component";
,其中/
指的是/src
文件夹(这样我就不必使用相对导入来导入所有函数)。
Next.js很好地解释了它,并没有抛出错误,但是ESLint却抛出了错误:Cannot find module '/path/to/component' or its corresponding type declarations. ts(2307)
。这真的让我很恼火,因为项目看起来有48个错误,而其中80%的错误只是来自这一个错误。
有没有办法可以强制ESLint完全忽略typescript错误(TS2307)?
提前感谢!
英文:
For clarification, my project is built with Next.js and Typescript. I've been importing my functions this way: import Component from "/components/Component/Component";
, where /
refers to the /src
folder (so I don't have to import all the functions with relative imports).
Next.js interprets it nicely and doesn't throw me an error, but ESLint does. For every line ESLint throws the error: Cannot find module '/path/to/component' or its corresponding type declarations. ts(2307)
. It really infuriates me because the project looks like it has 48 errors while 80% of those errors are just from that one error.
Is there any way I can force ESLint to completely ignore the typescript error (TS2307)?
Thanks in advance!
答案1
得分: 0
这不是常见的做法,从根目录开始导入。我建议在tsconfig.json中添加baseUrl属性(如果还没有的话)。
"baseUrl": "./"
之后,你可以像这样导入你的组件:
import Component from "components/Component/Component";
英文:
It is not really common practice to start import from /. I would suggest adding baseUrl property to tsconfig.json if you don't have it already
"baseUrl": "./"
After that you can import your components like this
import Component from "components/Component/Component";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论