Node.js 巴别塔模块分解器不';无法按预期工作(节点和类型脚本)
在我的节点项目中,我使用巴别塔插件模块解析器(babel plugin module resolver)来获得相对路径 tsconfig.json .eslintrc .babelrc 当我导入文件时,它不会显示任何错误。可以通过单击导入路径移动到特定文件。但当它符合时,它会给出以下错误Node.js 巴别塔模块分解器不';无法按预期工作(节点和类型脚本),node.js,typescript,babeljs,eslint,babel-plugin-module-resolver,Node.js,Typescript,Babeljs,Eslint,Babel Plugin Module Resolver,在我的节点项目中,我使用巴别塔插件模块解析器(babel plugin module resolver)来获得相对路径 tsconfig.json .eslintrc .babelrc 当我导入文件时,它不会显示任何错误。可以通过单击导入路径移动到特定文件。但当它符合时,它会给出以下错误 如何解决此问题???看起来您的TS配置文件的路径与Babel配置文件的别名字段不匹配。正如@jered在问题注释中指出的那样,尝试在有问题的导入中添加前缀@ 正如@pasi所说,您还可以看到关于ts节点和路径的
如何解决此问题???看起来您的TS配置文件的
路径与Babel配置文件的别名
字段不匹配。正如@jered在问题注释中指出的那样,尝试在有问题的导入中添加前缀@
正如@pasi所说,您还可以看到关于ts节点
和路径
的详细讨论。您的tsconfig“path”和babel config“alias”字段似乎不匹配。如果在库文件夹的.babelrc
中编辑条目以添加@
,会发生什么情况<代码>“@library:”/src/library“,
是否仅从@library
导入有问题,还是存在其他有问题的导入?有关ts节点
和路径
的详细讨论,请参阅
{
"compilerOptions": {
"outDir": "build",
"target": "es5",
"module": "commonjs",
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "./src",
"paths": {
"constants/*": ["constants/*"],
"data/*": ["data/*"],
"database/*": ["database/*"],
"enums/*": ["enums/*"],
"features/*": ["features/*"],
"@library/*": ["library/*"],
}
}
}
{
"parser": "@typescript-eslint/parser",
"extends": ["plugin:@typescript-eslint/recommended"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"import/resolver": {
"babel-module": {}
}
},
"rules": {
"semi": ["warn", "always"],
"quotes": ["warn", "single"],
"max-len": ["warn", 150],
"no-console": 1,
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-inferrable-types": [
"warn", {
"ignoreParameters": true
}
]
}
}
{
"presets": [
"@babel/preset-typescript",
"@babel/preset-env"
],
"plugins": [
[
"module-resolver",
{
"alias": {
"config": "./src/config",
"constants": "./src/constants",
"data": "./src/data",
"enums": "./src/enums",
"features": "./src/features",
"library": "./src/library",
"middleware": "./src/middleware",
"utils": "./src/utils"
}
}
]
]
}