部署Firebase Typescript函数出错; unmarshalling package.json:json:无法将bool解封到Go结构域PackageJSON.devDependencies

hivapdat  于 2023-05-18  发布在  TypeScript
关注(0)|答案(1)|浏览(90)

我试图将一个云函数部署到firebase,我得到了以下错误消息。
构建失败:unmarshalling package.json:json:无法将bool解组到Go结构字段PackageJSON.devDependencies of type string;错误ID:404111111
这是我的索引。ts

import * as functions from 'firebase-functions';
import retrievePositionData from './retrievePositionData';

const admin = require('firebase-admin');
admin.initializeApp();

export const fetchLocations = functions.pubsub
  .schedule('*/10 * * * *')
  .timeZone('America/Montreal')
  .onRun(retrievePositionData);

这是我的自定义函数拉取JSON以写入Firestore retrievePositionData. ts。

import axios from "axios";
import { firestore } from 'firebase-admin';
import { Client, ElevationResponse } from "@googlemaps/google-maps-services-js";
import { config } from 'firebase-functions';

type SpotResponse = {
  response: {
    feedMessageResponse: {
      count: number,
      messages: {
        message: Array<{
          latitude: number,
          longitude: number,
          unixTime: number,
          messageType: string,
          messageContent: string,
          batteryState: string,
        }>,
      },
    },
    errors: Array<{}>,
  },
}

export default async () => {
  const client = new Client({});
  const FirestoreInstance = firestore();
  const feedID = '0u88e3hrgRoCDA4JEqkg41U1jhO25PbvW';
  let offset = 0;
  while (true) {
    const url = `https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/${feedID}/message.json?start=${offset}`;
    const response = await axios.get<SpotResponse>(url)
    if (response.data.response.errors) {
      console.log('Reached the end of the feed. Stopping.');
      return;
    }
    const messages = response.data.response.feedMessageResponse.messages.message;

    while (messages.length > 0) {
      const message = messages.shift();
      if (!message) throw new Error('No more items in the queue');

      const query = await FirestoreInstance.collection('locationHistory').where('timestamp', '==', firestore.Timestamp.fromMillis(message.unixTime * 1000)).limit(1).get();
      if(!query.empty) {
        console.log('Found duplicate entry. Stopping.');
        return;
      }

      const elevationResponse: ElevationResponse = await client.elevation({
        params: {
          locations: [{ lat: message.latitude, lng: message.longitude }],
          key: config().maps.key,
        },
        timeout: 1000,
      });
      
      const formatedMessage: any = {
        timestamp: firestore.Timestamp.fromMillis(message.unixTime * 1000),
        location: new firestore.GeoPoint(message.latitude, message.longitude),
        messageType: message.messageType,
        messageContent: message.messageContent,
        batteryState: message.batteryState,
        elevation: elevationResponse.data.results[0].elevation,
      }
      Object.keys(formatedMessage).forEach(key => formatedMessage[key] === undefined && delete formatedMessage[key]);

      FirestoreInstance.collection('locationHistory').doc().create(formatedMessage)
        .then((value: firestore.WriteResult) => {
          console.log('Successfully inserted document', formatedMessage, 'at', value.writeTime);
        })
        .catch((reason: any) => {
          console.error('Could not insert document', reason);
        });
    }

    offset += response.data.response.feedMessageResponse.count;
  }
}

这是package.json

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@googlemaps/google-maps-services-js": "^3.1.4",
    "axios": "^0.19.2",
    "express": "^4.17.1",
    "firebase-admin": "^8.10.0",
    "firebase-functions": "^3.6.1"
  },
  "devDependencies": {
    "tslint": "^5.12.0",
    "typescript": "^4.9.4",
    "firebase-functions-test": "^0.2.0",

    "private": true
  }
}
rqenqsqc

rqenqsqc1#

从package.json中删除此行。它不是一个devDependency,但你有它嵌套在那里:

"private": true

相关问题