错误:加载firebase.json时出错:未安装Bolt,运行npm install -g firebase-bolt

时间:2016-09-13 22:35:02

标签: javascript json node.js firebase npm

操作系统:Windows 10 Pro
节点:6.1.0
NPM:3.8.6
Gulp:CLI版本3.9.1

因此,使用npm install -g firebase-bolt全局安装了firebase-bolt。但是,在运行构建过程时,我收到以下错误消息:



Error: There was an error loading firebase.json:

Bolt not installed, run npm install -g firebase-bolt
[21:47:04] 'deploy-firebase' errored after 8.29 s
[21:47:04] Error: 1
    at formatError (C:\Users\d0475\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:169:10)
    at Gulp.<anonymous> (C:\Users\d0475\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:195:15)
    at emitOne (events.js:101:20)
    at Gulp.emit (events.js:188:7)
    at Gulp.Orchestrator._emitTaskDone (C:\Users\d0475\Documents\Projects\esteMasterApp2\node_modules\orchestrator\index.js:264:8)
    at C:\Users\d0475\Documents\Projects\esteMasterApp2\node_modules\orchestrator\index.js:275:23
    at finish (C:\Users\d0475\Documents\Projects\esteMasterApp2\node_modules\orchestrator\lib\runTask.js:21:8)
    at ChildProcess.cb (C:\Users\d0475\Documents\Projects\esteMasterApp2\node_modules\orchestrator\lib\runTask.js:29:3)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at ChildProcess.cp.emit (C:\Users\d0475\Documents\Projects\esteMasterApp2\node_modules\cross-spawn\lib\enoent.js:40:29)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
&#13;
&#13;
&#13;

部署-firebase.js

&#13;
&#13;
import spawn from 'cross-spawn';
import gulp from 'gulp';

gulp.task('deploy-firebase', ['to-html'], done => {
  // childProcess
  spawn('firebase', ['deploy'], { stdio: 'inherit' })
  .on('close', done);
});
&#13;
&#13;
&#13;

到html.js

&#13;
&#13;
const urls = {
  '/': 'index.html',
  '/404': '404.html',
};

gulp.task('to-html', done => {
  args.production = true;
  process.env.IS_SERVERLESS = true;

  const fetch = url => new Promise((resolve, reject) => {
    http.get({ host: 'localhost', path: url, port: 3000 }, res => {
      // Explicitly treat incoming data as utf8 (avoids issues with multi-byte).
      res.setEncoding('utf8');
      let body = '';
      res.on('data', data => {
        body += data;
      });
      res.on('end', () => resolve(body));
    }).on('error', reject);
  });

  const moveAssets = () => {
    const assets = fs.readdirSync('build');
    fs.mkdirSync(path.join('build', 'assets'));
    assets.forEach(fileName => {
      fs.renameSync(
        path.join('build', fileName),
        path.join('build', 'assets', fileName)
      );
    });
  };

  const toHtml = () => {
    const promises = Object.keys(urls).map(url => fetch(url).then(html => {
      fs.writeFile(path.join('build', urls[url]), html);
    }));
    return Promise.all(promises);
  };

  runSequence('eslint-ci', 'ava', 'flow', 'clean', 'build', () => {
    const proc = spawn('node', ['./src/server']);
    proc.stderr.on('data', data => console.log(data.toString()));
    proc.stdout.on('data', async data => {
      data = data.toString();
      if (data.indexOf('Server started') === -1) return;
      try {
        moveAssets();
        await toHtml();
      } catch (error) {
        console.log(error);
      } finally {
        proc.kill();
        done();
        console.log('App has been rendered to /build directory.');
        console.log('OSX tip: cd build && python -m SimpleHTTPServer 3000');
      }
    });
  });
});
&#13;
&#13;
&#13;

firebase.json

&#13;
&#13;
{
  "database": {
    "rules": "./firebase/rules.bolt"
  },
  "hosting": {
    "public": "build",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "headers": [
      {
        "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
        "headers" : [{
          "key" : "Access-Control-Allow-Origin",
          "value" : "*"
        }]
      }, {
        "source" : "**/*.@(jpg|jpeg|gif|png)",
        "headers" : [{
          "key" : "Cache-Control",
          "value" : "max-age=7200"
        }]
      }
    ],
    "cleanUrls": true,
    "trailingSlash": false
  }
}
&#13;
&#13;
&#13;

rules.bolt

&#13;
&#13;
// An example of Firebase security and modeling language.
// https://github.com/firebase/bolt/blob/master/docs/guide.md

// Functions

isSignedIn() { auth != null }
isViewer(uid) { isSignedIn() && auth.uid == uid }
isFriend(uid) { true } // We can limit access to sensitive data easily.

// Types

// github.com/firebase/bolt/blob/master/docs/guide.md#dealing-with-timestamps
type CurrentTimestamp extends Number {
  validate() { this == now }
}

type ShortString extends String {
  validate() { this.length <= 100 }
}

type ShortRequiredString extends String {
  // Required form field with maxLength="100".
  validate() { this.length > 0 && this.length <= 100 }
}

type LongString extends String {
  validate() { this.length <= 1000 }
}

type LongRequiredString extends String {
  validate() { this.length > 0 && this.length <= 1000 }
}

type ExtraLongString extends String {
  validate() { this.length <= 10000 }
}

type ExtraLongRequiredString extends String {
  validate() { this.length > 0 && this.length <= 10000 }
}

type HelloWorld {
  createdAt: CurrentTimestamp,
  text: ShortString
}

type User {
  displayName: LongString,
  id: ShortRequiredString,
  photoURL: LongString,
  validate() { this.id == auth.uid }
}

type UserEmail {
  email: ShortRequiredString
}

type UserPresence {
  authenticatedAt: CurrentTimestamp,
  user: User
}

// Paths

path /hello-world is HelloWorld {
  // Anyone can create, read, update. No one can delete.
  create() { true }
  read() { true }
  update() { true }
}

path /users/{uid} is User {
  read() { isFriend(uid) }
  write() { isViewer(uid) }
}

path /users-emails/{uid} is UserEmail {
  read() { isViewer(uid) }
  write() { isViewer(uid) }
}

path /users-presence {
  read() { true } // Sure we can limit access here as well.
}

path /users-presence/{uid} is UserPresence[] {
  create() { isViewer(uid) }
  update() { true }
  delete() { true }
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

这是一个众所周知的问题:firebase-bolt not found on Windows #205

Google更新firebase-tools时,解决方案是使用提到的包npm install -g oscar-b/firebase-tools