0

I have a folder which holds the JSON file of my Firebase db's, I have a .bat file in Windows which uploads the db's at once. Now I want to duplicate it to MAC.

This is the folder hierarchy:

  • package-lock.json
  • node_modules (Folder)
  • GAME_NAME (Folder)
    • config.js
    • serviceAccount.json
    • Dev (Folder)
      • import_data.js
      • upload.sh -> This file i'm running
      • data (Folder)
        • Data-worldwide.json

When running upload.sh:

#! /bin/bash
node import_data.js

import_data.js:

// Imports
const firestoreService = require('..\..\node_modules\firestore-export-import');
const firebaseConfig = require('..\config.js');
const serviceAccount = require('..\serviceAccount.json');

// JSON To Firestore
const jsonToFirestore = async () => {
  try {
    console.log('Initialzing Firebase');
    await firestoreService.initializeApp(serviceAccount, firebaseConfig.databaseURL);
    console.log('Firebase Initialized');

    await firestoreService.restore('./data/Data-worldwide.json');
    console.log('Upload Success');
  }
  catch (error) {
    console.log(error);
  }
};

jsonToFirestore();

I'm keep getting this error:

xxxxxx@164 Dev % ./upload.sh
internal/modules/cjs/loader.js:651
    throw err;
    ^

Error: Cannot find module '....
ode_modules
           irestore-export-import'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:649:15)
    at Function.Module._load (internal/modules/cjs/loader.js:575:25)
    at Module.require (internal/modules/cjs/loader.js:705:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/xxxx/Dropbox/JSON Databases/GAME_NAME/Dev/import_data.js:2:26)
    at Module._compile (internal/modules/cjs/loader.js:799:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)
    at Module.load (internal/modules/cjs/loader.js:666:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:606:12)
    at Function.Module._load (internal/modules/cjs/loader.js:598:3)
internal/modules/cjs/loader.js:651
    throw err;
    ^

Error: Cannot find module '....
ode_modules
           irestore-export-import'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:649:15)
    at Function.Module._load (internal/modules/cjs/loader.js:575:25)
    at Module.require (internal/modules/cjs/loader.js:705:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/xxxx/Dropbox/JSON Databases/GAME_NAME/Dev/import_data.js:2:26)
    at Module._compile (internal/modules/cjs/loader.js:799:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)
    at Module.load (internal/modules/cjs/loader.js:666:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:606:12)
    at Function.Module._load (internal/modules/cjs/loader.js:598:3)
2
  • require('firestore-export-import') should be enough. Is the module installed? Commented Dec 27, 2020 at 11:50
  • What do you mean by "installed"? I just copied it from the Windows folder. Commented Dec 27, 2020 at 12:45

1 Answer 1

2

In JavaScript string literals a \ is an escape character.

To have a literal \ in a string you need to escape it: \\ … but Node.js generally uses UNIX-style directory separators (/) and not Windows ones anyway.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.