Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Deploying Firebase Typescript Function Error; unmarshalling package.json: json: cannot unmarshal bool into Go struct field PackageJSON.devDependencies

I’m trying to deploy a cloud function to firebase and I’m getting the following error message.

Build failed: unmarshalling package.json: json: cannot unmarshal bool into Go struct field PackageJSON.devDependencies of type string; Error ID: 9f520bcf

This is my index.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);

This is my custom function pulling JSON to write to 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;
  }
}

And this is 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
  }
}

>Solution :

Remove this line from package.json. It’s not a devDependency, yet you have it nested there:

    "private": true
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading