タグ: firebase

  • firebase deploy時のeslintを無効にする

    firebase deploy時のeslintを無効にする

    はじめに

    firebase functionを使えるようにした際、知らず知らずにESLintを有効にしてしまっていた。今回は対処した際の方法を紹介。

    問題

    firebase deploy
    
    === Deploying to 'auth-xxx'...
    
    i  deploying database, functions, hosting
    Running command: npm --prefix "$RESOURCE_DIR" run lint
    
    > functions@ lint /Users/coco/Documents/firebase-auth/functions
    > eslint .
    
    
    /Users/coco/Documents/firebase-auth/functions/index.js
      31:7   error    Expected return with your callback function                     callback-return
      38:24  warning  Use path.join() or path.resolve() instead of + to create paths  no-path-concat
    
    ✖ 2 problems (1 error, 1 warning)
    
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! functions@ lint: `eslint .`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the functions@ lint script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/coco/.npm/_logs/2019-12-10T15_36_22_429Z-debug.log
    
    Error: functions predeploy error: Command terminated with non-zero exit code1
    darkenagy:firebase-auth coco$ cat /Users/coco/.npm/_logs/2019-12-10T15_36_22_429Z-de

    ESLintで引っかかっているようだ。

    ふりかえり

    そもそも、本当にESLintを有効にしたんだっけ。。
    どのようにfirebase functionを有効にしたか振り返る。

    firebase init functions
    
         ######## #### ########  ######## ########     ###     ######  ########
         ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
         ######    ##  ########  ######   ########  #########  ######  ######
         ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
         ##       #### ##     ## ######## ########  ##     ##  ######  ########
    
    You're about to initialize a Firebase project in this directory:
    
      /Users/coco/Documents/firebase-auth
    
    Before we get started, keep in mind:
    
      * You are initializing in an existing Firebase project directory
    
    
    === Project Setup
    
    First, let's associate this project directory with a Firebase project.
    You can create multiple project aliases by running firebase use --add, 
    but for now we'll just set up a default project.
    
    i  .firebaserc already has a default project, using auth-xxx.
    
    === Functions Setup
    
    A functions directory will be created in your project with a Node.js
    package pre-configured. Functions can be deployed with firebase deploy.
    
    ? What language would you like to use to write Cloud Functions? JavaScript
    ? Do you want to use ESLint to catch probable bugs and enforce style? Yes
    ✔  Wrote functions/package.json
    ✔  Wrote functions/.eslintrc.json
    ✔  Wrote functions/index.js
    ✔  Wrote functions/.gitignore
    ? Do you want to install dependencies with npm now? Yes
    
    > protobufjs@6.8.8 postinstall /Users/coco/Documents/firebase-auth/functions/node_modules/protobufjs
    > node scripts/postinstall
    
    npm notice created a lockfile as package-lock.json. You should commit this file.
    added 344 packages from 245 contributors and audited 869 packages in 11.579s
    found 0 vulnerabilities
    
    
    i  Writing configuration info to firebase.json...
    i  Writing project information to .firebaserc...
    
    ✔  Firebase initialization complete!
    
    
       ╭───────────────────────────────────────────╮
       │                                           │
       │      Update available 7.8.1 → 7.9.0       │
       │   Run npm i -g firebase-tools to update   │
       │                                           │
       ╰───────────────────────────────────────────╯
    

    しっかりESLintを有効にしてた。

    現在の設定を確認

    firebase.jsonを確認する

    cat firebase.json 
    {
      "database": {
        "rules": "database.rules.json"
      },
      "hosting": {
        "public": "public",
        "rewrites": [
          {
            "source": "**",
            "function": "firebaseAuth"
          }
        ],
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ]
      },
      "functions": {
        "predeploy": [
          "npm --prefix \"$RESOURCE_DIR\" run lint"
        ]
      }
    }

    黄色の箇所を削除し、再度“` firebase deploy“`を行うと、ESlintが行われずdeployされる。

    参考情報