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

Deployments to GCP not working #1

Open
alexabbott opened this issue Jan 4, 2021 · 2 comments
Open

Deployments to GCP not working #1

alexabbott opened this issue Jan 4, 2021 · 2 comments

Comments

@alexabbott
Copy link

alexabbott commented Jan 4, 2021

Upon running npm run deploy the following error is presented:

message=Build failed: function.js does not exist; Error ID: 7485c5b6

After changing server.js to function.js the following error is presented:

 message=Function failed on loading user code. This is likely due to a bug in the user code.
@marceloogeda
Copy link

marceloogeda commented Nov 25, 2021

I faced the same issue.

I've configured the following Github Actions to deploy to gcf.

name: Deploy on GCF (Production)

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      - name: Read .nvmrc file
        run: echo ::set-output name=NVMRC::$(cat .nvmrc)
        id: nvm

      - name: Use Node.js (.nvmrc)
        uses: actions/setup-node@v1
        with:
          node-version: "${{ steps.nvm.outputs.NVMRC }}"

      - name: Install dependencies
        run: |
          npm i

      - name: Build
        run: |
          npm ci --legacy-peer-deps
          npm run build

      - name: Setup Google Cloud
        uses: actions-hub/gcloud@master
        env:
          PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID_PROD }}
          APPLICATION_CREDENTIALS: ${{ secrets.GCLOUD_SERVICE_KEY_PROD }}

      - name: Delpoy to GCP
        uses: actions-hub/gcloud@master
        with:
          args: |
            functions deploy \
            --project ${{ secrets.GOOGLE_PROJECT_ID_PROD }} \
            functionName \
            --entry-point handler \
            --trigger-http \
            --runtime nodejs12 \
            --memory=128MB \
            --allow-unauthenticated

I also needed to create my own .gcloudignore file.

I hope it helps.

@antun
Copy link

antun commented Jun 6, 2023

Update: I got this working, and forked this repo and made some updates. (The file rename above, and changes to the README and update to Node 16.)

Here's my fork: https://github.com/antun/nextjs-google-cloud-functions

Here's the PR: #2


@marceloogeda I'm looking at your GitHub Action, and I don't see anything significantly different from the deployment command I'm using:

gcloud functions deploy nextjs --entry-point=handler --allow-unauthenticated --trigger-http --runtime=nodejs16 --memory=128MB --project MY_PROJECT_ID

I've also renamed server.js to function.js like @alexabbott did. The error I get is:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. This is likely due to a bug in the user code. Error message: Provided module can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/workspace/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///workspace/function.js:1:14
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
at async getUserFunction (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/loader.js:93:30)
at async main (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/main.js:35:32)
Could not load the function, shutting down.. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.

antun added a commit to antun/nextjs-google-cloud-functions that referenced this issue Jun 7, 2023
antun added a commit to antun/nextjs-google-cloud-functions that referenced this issue Jun 7, 2023
antun added a commit to antun/nextjs-google-cloud-functions that referenced this issue Jun 7, 2023
antun added a commit to antun/nextjs-google-cloud-functions that referenced this issue Jun 7, 2023
antun added a commit to antun/nextjs-google-cloud-functions that referenced this issue Jun 7, 2023
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

3 participants