- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
根据 this solution,我通过 tsconfig.json
中的 baseUrl
编译器选项使用根目录相对导入,但我遇到了一个问题,Atom IDE 向我显示如下所示的 linting 错误:
Cannot find module 'core/nav-menu/nav-menu.component'.
导入看起来像(在 src/app/core/nav-menu.module.ts
中):
import { NavMenuComponent } from 'core/nav-menu/nav-menu.component';
Atom 中的 TSLint 没有找到与根目录相关的导入文件,但 Angular 编译器对它们没有问题。
我不确定我的 tslint.json
配置是否错误...在我在同一台机器上的另一个项目中,一切都按预期工作,但我无法发现这个项目有什么不同,导致了这个问题。
tslint.json:
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"arrow-return-shorthand": true,
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"deprecation": {
"severity": "warn"
},
"eofline": true,
"forin": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-arg": true,
"no-bitwise": true,
"no-console": [
true,
"debug",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": true,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-misused-new": true,
"no-non-null-assertion": true,
"no-shadowed-variable": true,
"no-string-literal": false,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unnecessary-initializer": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"prefer-const": true,
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": [
true,
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"unified-signatures": true,
"variable-name": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"no-output-on-prefix": true,
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true
}
}
src/tslint.json:
{
"extends": "../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"s2es",
"camelCase"
],
"component-selector": [
true,
"element",
"s2es",
"kebab-case"
]
}
}
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "app",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
src/tsconfig.app.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": [],
"baseUrl": "app",
"types": ["node"]
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
附带说明一下,为什么 baseUrl: "app"
不是默认值?为什么文件相对导入看起来像是 Angular/TypeScript 开发的标准。太疯狂了。
最佳答案
您的基本网址错误:
您的 tsconfig.json 必须设置为:"baseurl": "./"
您的 tsconfig.app.ts 中不需要 baseurl
,应该将其删除。
正如评论中所建议的,导入路径也应该更新。在导入路径前添加'src/app'。
如果你的结构如下并且你运行的是 Angular 6,这适用:
* project
| - src
| | - app (with app files like app.modules.ts)
| | - tsconfig.app.json
| - tsconfig.json
也许您在试图找出问题所在时篡改了文件。这也是新生成的 Angular 项目的标准配置。
关于angular - typescript /TSLint : TSLint not recognizing root-relative imports via baseUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51292139/
我使用react-scripts-ts来生成React App,它提供了TSLint。 似乎没有选项可以告诉 react-scripts-ts 从构建管道中排除 TSLint。是否可以通过 tslin
如何禁用命名导入必须按字母顺序排列 - tslint ? 我收到错误: 命名的导入必须按字母顺序排列。 我不知道如何禁用此错误。 我的 tsconfig.json 配置是: { "compil
我查看了文档,但无法弄清楚 TSLint 中规则的默认值是什么。如果我没有指定此处找到的规则之一( https://palantir.github.io/tslint/rules/ ),那么它是否默认
我想知道是否有 TSLint 规则可以禁止以下代码: var arr = [1, 2]; //the line below should be disallowed arr.prop1 = "3";
clearFile() { (document.getElementById('uploadFile')).value = ""; } 给 [tslint] misplaced ope
我收到此 tslint 错误,我不明白为什么。该界面确实以大写字母开头。 29 第 11 栏错误|接口(interface)名称必须以大写的 I(接口(interface)名称)[typescript
我需要不允许 tslint 修复发现的错误。例如,如果它发现逗号丢失,我只需要它告诉我它找到了它,而不是实际修复它。 我在它的 vue-cli 文档中找到了“--no-fix”参数,但看起来它不起作用
我正在使用 the Angular starter kit 我正在尝试让 tslint 使用 --fix 标志自动修复我所有的 lint 问题。 我正在运行脚本:npm run tslint --fi
我正在尝试为 VueJS 项目中的代码块禁用 TSlint(版本:typescript 3.5.2,tslint 5.18.0),但它似乎不起作用(它仍然在编译时显示此 block 的错误和警告npm
我以前用 rxjs-tslint-rules包来了解我的项目中与 RxJS 相关的问题。它被添加到我项目的 package.json 文件的 devDependencies 部分。 现在,有 rxjs
当我尝试运行命令 ng lint --fix cli 抛出此错误: An unhandled exception occurred: Cannot find builder "@angular-dev
我们最近将我们的 Angular 2 项目升级到了 @angular/cli 1.0 版。我们还将 tslint 从 2.x 升级到 5.x。现在我们在设计时(在 VSCode 输出终端中)收到以下
根据 this solution,我通过 tsconfig.json 中的 baseUrl 编译器选项使用根目录相对导入,但我遇到了一个问题,Atom IDE 向我显示如下所示的 linting 错误
我有一个用 TypeScript 为 TSlint 编写的自定义规则,我可以在我的 Linux VM 上使用的脚本中使用 ts-node 运行它: #!/bin/bash set -e ROOT_DI
默认情况下,在 angular-cli 项目中,tslint 设置包含了一些会弯曲的东西。最近,一位新开发人员联系我,说我在 Atom 中配置了他们的 tslint 实例。 我被问及以下行: impo
这是我们的环境 > \node_modules\.bin\tslint --version 4.0.1 > npm install --save-dev tslint-microsoft-contri
我的 tslint.json 如下所示 { "defaultSeverity": "error", "extends": [ "tslint:recommended"
大家好,npm 有问题和 tslint我希望你能帮助我。 好的,我的情况和代码来了: package.json "scripts": { "lint": "tslint -c tslint.j
我正在尝试配置我的TSLint规则ordered-imports以使导入顺序如下所示: // React import React from 'react'; import { View } from
我的 tslint.json 中有以下规则: "member-ordering": [ true, { "order": [
我是一名优秀的程序员,十分优秀!