Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
332 stars 57 forks source link

Build and Deploy Job failed after adding ESLint and Prettier to API #625

Open phwt opened 3 years ago

phwt commented 3 years ago

Describe the bug

I am trying to configure the API project built with TypeScript with ESLint and Prettier but after I add it the "Build and Deploy Job" is failed with this message:

The function language detected is unsupported or invalid. The following languages are valid: dotnet, dotnetisolated, node, python. If you are not using Azure Functions, you can skip this check by removing the 'api_location' input from the workflow file.

To Reproduce Here are the steps I've taken on setting up the ESLint and Prettier:

  1. Install ESLint, Prettier, and its plugins
    npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint \
    eslint-config-airbnb-base eslint-config-airbnb-typescript \
    eslint-config-prettier eslint-plugin-import eslint-plugin-prettier prettier
  2. Run eslint --init to generate .eslintrc.js

Difference in project files

.eslintrc.js

+ module.exports = {
+     "env": {
+         "es2021": true,
+         "node": true
+     },
+     "parser": "@typescript-eslint/parser",
+     "parserOptions": {
+         "ecmaVersion": 12,
+         "sourceType": "module"
+     },
+     "plugins": [
+         "@typescript-eslint"
+     ],
+     "rules": {
+     }
+ };

package.json

      "start:host": "func start",
      "start": "npm-run-all --parallel start:host watch",
      "test": "jest",
-     "generate-spec": "tsoa spec"
+     "generate-spec": "tsoa spec",
+     "lint": "eslint .",
+     "format": "prettier --write './**/*.{js,ts,css,md,json}' --config ./.prettierrc"
  },
  "description": "",
  "devDependencies": {
  @@ -20,9 +22,18 @@
      "@babel/preset-typescript": "^7.15.0",
      "@types/jest": "^27.0.2",
      "@types/node": "^16.11.3",
+     "@typescript-eslint/eslint-plugin": "^5.3.1",
+     "@typescript-eslint/parser": "^5.3.1",
      "babel-jest": "^27.3.1",
+     "eslint": "^7.32.0",
+     "eslint-config-airbnb-base": "^14.2.1",
+     "eslint-config-airbnb-typescript": "^15.0.0",
+     "eslint-config-prettier": "^8.3.0",
+     "eslint-plugin-import": "^2.25.2",
+     "eslint-plugin-prettier": "^4.0.0",
      "jest": "^27.2.4",
      "npm-run-all": "^4.1.5",
+     "prettier": "^2.4.1",
      "ts-jest": "^27.0.5",
      "typescript": "^4.4.4"
  },

Expected behavior

Additional context

dombarnes commented 3 years ago

What does your build script in package.json do?

phwt commented 3 years ago

What does your build script in package.json do?

It generates an OpenAPI specification with tsoa and then starts compilation with tsc

"build": "npm run generate-spec && tsc",
"generate-spec": "tsoa spec"
Here's the rest of the "package.json" file ```json { "name": "api", "version": "1.0.0", "scripts": { "build": "npm run generate-spec && tsc", "build:production": "npm run prestart && npm prune --production", "watch": "tsc --w", "prestart": "npm run build && func extensions install", "start:host": "func start", "start": "npm-run-all --parallel start:host watch", "test": "jest", "generate-spec": "tsoa spec", "lint": "eslint .", "format": "prettier --write './**/*.{js,ts,css,md,json}' --config ./.prettierrc" }, "description": "", "devDependencies": { "@azure/functions": "^1.0.1-beta1", "@babel/core": "^7.15.8", "@babel/plugin-proposal-decorators": "^7.15.4", "@babel/preset-env": "^7.15.8", "@babel/preset-typescript": "^7.15.0", "@types/jest": "^27.0.2", "@types/node": "^16.11.3", "@typescript-eslint/eslint-plugin": "^5.3.1", "@typescript-eslint/parser": "^5.3.1", "babel-jest": "^27.3.1", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-config-airbnb-typescript": "^15.0.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.25.2", "eslint-plugin-prettier": "^4.0.0", "jest": "^27.2.4", "npm-run-all": "^4.1.5", "prettier": "^2.4.1", "ts-jest": "^27.0.5", "typescript": "^4.4.4" }, "dependencies": { "@typegoose/typegoose": "^9.0.1", "babel-plugin-transform-typescript-metadata": "^0.3.2", "dayjs": "^1.10.7", "mongoose": "^6.0.8", "tsoa": "^3.13.0" } } ```