【问题标题】:NPM: No valid rules have been specified for TypeScript filesNPM:没有为 TypeScript 文件指定有效规则
【发布时间】:2019-01-17 00:57:40
【问题描述】:

我正在用 React.JS 编写小项目。每次我运行:npm run start,它都会记录:

Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
Watching: /Users/John/Projects/myProject/src
Starting the development server...

ts-loader: Using typescript@2.9.2 and /Users/John/Projects/myProject/tsconfig.json

没有为 TypeScript 文件指定有效规则

Compiled successfully!
You can now view book-viewer-test in the browser.
Local:            http://localhost:3000/

我已经突出显示了错误所在的行。一切都很好,但我担心当项目变得更大更复杂时它会产生影响。

这是什么警告/错误?我该如何解决?

这是我的 tsconfig.json 文件:

{
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es7", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "experimentalDecorators": true
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ]
}

还有 tslint.json 文件:

{
  "jsRules": {
    "no-empty": true
  }
}

感谢您的建议。

【问题讨论】:

    标签: javascript json reactjs typescript npm


    【解决方案1】:

    唯一适用于 JavaScript 文件的 TSLint 规则,而不是 TypeScript 文件。为了对 TypeScript 文件进行 lint,请使用 rules 而不是 jsRules

    {
      "rules": {
        "no-empty": true
      }
    }
    

    【讨论】:

    • 现在是No valid rules have been specified for JavaScript files
    【解决方案2】:

    您应该检查您使用的版本,因为没有定义任何规则,所以可能没什么大不了的! 无论如何,如果你有 react、npm、node 更新,你应该或多或少有这样的输出:

    PS C:\React\my-app> npm run start
    
    > my-app@0.1.0 start C:\React\my-app
    > react-scripts start
    Starting the development server...
    Compiled successfully!
    
    You can now view my-app in the browser.
    
      Local:            http://localhost:3000/
      On Your Network:  http://192.168.1.67:3000/
    
    Note that the development build is not optimized.
    To create a production build, use npm run build.
    

    【讨论】:

      【解决方案3】:

      这看起来像是一个 TSLint 错误。你有安装 TSLint 吗?介意分享您的package.json 吗?你有tslint.json,如果有,你能分享一下吗? (使用您想要的规则创建一个tslint.json 可能已经解决了它。)

      【讨论】:

        【解决方案4】:

        解决方案是将其添加到项目目录中的tslint.json

        {
            "rules": {
                "no-empty": false
            },
            "jsRules": {
                "no-empty": true
            }
         }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-05-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-05-10
          相关资源
          最近更新 更多