Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use import statement outside a module #68

Open
timstoute opened this issue May 31, 2023 · 2 comments
Open

Cannot use import statement outside a module #68

timstoute opened this issue May 31, 2023 · 2 comments
Assignees

Comments

@timstoute
Copy link

While deploying a TypeScript Firebase Cloud Function with the command:

firebase deploy --only functions:mapsRegionSearch

I'm seeing the error:

Error: Failed to load function definition from source: Failed to generate manifest from function source: SyntaxError: Cannot use import statement outside a module

I've isolated the issue / error to the specific cloud function shown below where I am using "@googlemaps/region-lookup"; all the other Cloud Functions in the project deploy without error when this Cloud Function is removed from the set.

Any insight on how to work around this error? I've followed the [documentation](https://developers.google.com/maps/documentation/javascript/dds-boundaries/region-lookup), but I'm stuck.

Node version 16.20.0
Firebase CLI version 12.2.1

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";

import { searchRegion, SearchRegionRequestData, SearchRegionResponse } from "@googlemaps/region-lookup";

export const mapsRegionSearch = functions.firestore
  .document("responses/{responseId}")
  .onCreate((change, context) => {
    if (change.data().coordinate) {
      return regionSearch(change, context);
    } else {
      console.log("this response did not have any coordinates attached");
      return;
    }
  });

async function regionSearch(change: any, context: any) {

  // Headers
  const headers: any = {
    "X-Goog-Api-Key": "XXXXX",
  };

  const data: SearchRegionRequestData = {
    search_values: [
      {
        latlng: change.data().coordinate,
        place_type: "administrative_area_level_1",
      },
    ],
  };

  const response: SearchRegionResponse = await searchRegion({ headers, data });

  console.log("region search returned this place id or error: ", response);

  if (response) {
    const db = admin.firestore();
    // do stuff
   
  }
}
@wangela
Copy link
Member

wangela commented May 31, 2023

If you would like to upvote the priority of this issue, please comment below or react with 👍 so we can see what is popular when we triage.

@timstoute Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

@BrunoPierca
Copy link

BrunoPierca commented Jun 12, 2023

I'm having the same issue
All my code is working properly and the module bundling works for every other package, its a nestJS application and i'm getting this error on compilation
`C:\Users\Bruno\Desktop\work\project\node_modules@googlemaps\region-lookup\dist\index.esm.js:34
import axios from "axios";
^^^^^^

SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1176:20)
at Module._compile (node:internal/modules/cjs/loader:1218:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Function.Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object. (C:\Users\Bruno\Desktop\work\project\src\maps\maps.service.ts:13:1)
at Module._compile (node:internal/modules/cjs/loader:1254:14)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants