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

Functions using ES modules wont deploy #4019

Closed
okydk opened this issue Jan 15, 2022 · 2 comments
Closed

Functions using ES modules wont deploy #4019

okydk opened this issue Jan 15, 2022 · 2 comments
Assignees

Comments

@okydk
Copy link

okydk commented Jan 15, 2022

[REQUIRED] Environment info

firebase-tools: 10.1.0

Platform: MacOS 12.1

[REQUIRED] Test case

index.js

import functions from 'firebase-functions'
import { initializeApp } from 'firebase-admin/app'

const app = initializeApp()

export const test = functions.https.onCall(async (docs, context) => {
	return {
		message: 'just a test'
	}
})

package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "main": "index.js",
  "type": "module",
  "engines": {
    "node": "16"
  },
  "dependencies": {
    "firebase-admin": "^10.0.1",
    "firebase-functions": "^3.16.0"
  }
}

[REQUIRED] Steps to reproduce

firebase deploy --only functions

[REQUIRED] Expected behavior

Function test deploying.

[REQUIRED] Actual behavior

Console error:

{"code":3,"message":"Build failed: (node:96) Warning: To load an ES module, set \"type\": \"module\" in the package.json or use the .mjs extension.\n(Use `node --trace-warnings ...` to show where the warning was created)\n/workspace/index.js:1\nimport functions from 'firebase-functions'\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n    at Object.compileFunction (node:vm:352:18)\n    at wrapSafe (node:internal/modules/cjs/loader:1031:15)\n    at checkSyntax (node:internal/main/check_syntax:66:3)\n    at node:internal/main/check_syntax:39:3; Error ID: d984e68f"}}
...
Functions deploy had errors with the following functions:
        test(us-central1)
[2022-01-15T09:47:19.396Z] Missing URI for HTTPS function in printTriggerUrls. This shouldn't happen
i  functions: cleaning up build files... 
[2022-01-15T09:47:19.398Z] >>> [apiv2][query] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/[PROJECT]/locations/us-central1/repositories/gcf-artifacts/packages/test [none]
[2022-01-15T09:47:19.399Z] >>> [apiv2][query] GET https://us.gcr.io/v2/[PROJECT]/gcf/us-central1/tags/list [none]
[2022-01-15T09:47:20.003Z] <<< [apiv2][status] GET https://us.gcr.io/v2/[PROJECT]/gcf/us-central1/tags/list 200
[2022-01-15T09:47:20.003Z] <<< [apiv2][body] GET https://us.gcr.io/v2/[PROJECT]/gcf/us-central1/tags/list {"child":[],"manifest":{},"name":"[PROJECT]/gcf/us-central1","tags":[]}
[2022-01-15T09:47:20.003Z] Could not find image for function projects/[PROJECT]/locations/us-central1/functions/test
[2022-01-15T09:47:20.415Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/[PROJECT]/locations/us-central1/repositories/gcf-artifacts/packages/test 404
[2022-01-15T09:47:20.415Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/[PROJECT]/locations/us-central1/repositories/gcf-artifacts/packages/test {"error":{"code":404,"message":"Repository does not exist: \"projects/[PROJECT]/locations/us-central1/repositories/gcf-artifacts\"","status":"NOT_FOUND"}}
[2022-01-15T09:47:20.419Z] Error: Failed to update function test in region us-central1
    at /Users/stefan/.nvm/versions/node/v16.13.2/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:38:11
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Fabricator.updateV1Function (/Users/stefan/.nvm/versions/node/v16.13.2/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:255:32)
    at async Fabricator.updateEndpoint (/Users/stefan/.nvm/versions/node/v16.13.2/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:136:13)
    at async handle (/Users/stefan/.nvm/versions/node/v16.13.2/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:75:17)

Error: There was an error deploying functions
@okydk
Copy link
Author

okydk commented Jan 15, 2022

Function works fine locally btw.

@taeold
Copy link
Contributor

taeold commented Jan 21, 2022

This is an issue with Node.js 16. If you can, please try deploy w/ Node 14 for now.

Duplicate of GoogleCloudPlatform/functions-framework-nodejs#407

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

No branches or pull requests

4 participants