simondotm / nx-firebase

Firebase plugin for Nx Monorepos
https://www.npmjs.com/package/@simondotm/nx-firebase
MIT License
175 stars 31 forks source link

Cloud Function Deployment Issue: "nx not found" #121

Closed aureliopetrone closed 1 year ago

aureliopetrone commented 1 year ago

When attempting to deploy a Cloud Function, I encounter an issue where the system is unable to find "nx". This happens because of the execution of the package.json build script. I believe there might be an option to deploy the function after building it locally, but I'm not certain.

Steps to reproduce:

Attempt to deploy a Cloud Function.

Error Message:

Cannot find "nx".

Expected behavior:

The build script in package.json should execute locally I guess. The Cloud Function should then be deployed successfully.

Additional context:

If there's a way to deploy the function after building it locally, that information would be helpful. If I've missed any steps that might lead to this issue or if further information is required, please let me know.

Node : 16.16.0 OS : darwin arm64 yarn : 3.4.1

nx : 15.3.3 @nrwl/angular : Not Found @nrwl/cypress : 15.3.3 @nrwl/detox : 15.3.3 @nrwl/devkit : 15.3.3 @nrwl/esbuild : Not Found @nrwl/eslint-plugin-nx : 15.3.3 @nrwl/expo : Not Found @nrwl/express : 15.3.3 @nrwl/jest : 15.3.3 @nrwl/js : 15.3.3 @nrwl/linter : 15.3.3 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : 15.3.3 @nrwl/nx-cloud : 15.3.3 @nrwl/nx-plugin : Not Found @nrwl/react : 15.3.3 @nrwl/react-native : 15.3.3 @nrwl/rollup : 15.3.3 @nrwl/schematics : Not Found @nrwl/storybook : Not Found @nrwl/web : 15.3.3 @nrwl/webpack : 15.3.3 @nrwl/workspace : 15.3.3 typescript : 4.9.5

Local workspace plugins:

Community plugins: @simondotm/nx-firebase: 1.0.0

simondotm commented 1 year ago

Try npx nx

aureliopetrone commented 1 year ago

I mean the build works locally. That error happens on cloud because when you deploy the package it executes the build script present in package.json, but since nx is not available it fails.

aureliopetrone commented 1 year ago

For example, changing build to build: "local" on the generated package.json after the building, and deploying manually solve the issue

I guess it's related to that, https://github.com/GoogleCloudPlatform/buildpacks/issues/287, and to be honest, updating firebasee tools worked at first, but even if i'm using 12.4 it suddenly stopped working again

aureliopetrone commented 1 year ago

Adding "gcp-build" with an empty value to the scripts in package.json solves the issue.

 "scripts": {
     ...
    "gcp-build":""
  },
simondotm commented 1 year ago

Ok great work. In all honesty I'm not fully understanding this issue, but glad to hear you resolved it.

aureliopetrone commented 1 year ago

@simondotm Essentially, what occurs is that GCloud is designed to automatically execute a user's build script upon package upload. An issue arises due to the build script's dependency on "nx", a tool installed on the local system. The absence of "nx" in the GCloud environment leads to a failed build script execution.

The Google Cloud Platform offers the possibility to personalize the build process by supplying an alternative to the standard build script. This function can be harnessed to address the prevailing issue. Essentially, the requirement is to generate a custom "gcp-build" script that can operate in the GCloud environment without the need for "nx".

The "gcp-build" script functions as a replacement for the default build script. Hence, upon package upload, GCloud identifies the existence of this "gcp-build" script and employs it instead of the regular build script designed for the local environment. By personalizing the build process in such a manner, compatibility with the tools and utilities present on GCloud can be ensured, thus evading problems due to the absence of "nx".

This method enables the continued use of "nx" for local builds, while also preserving a compatible build process for deployments to GCloud.