nx-extend: Google Cloud functions framework not working when upgrading Nx from 17.0.3 -> 17.1.3

Running a cloud function used to work with v17.0.x

npx @google-cloud/functions-framework --source=dist/apps/cloud-functions --target=CloudFunctions

Function 'CloudFunctions' is not defined in the provided module.
Did you specify the correct target function to execute?
Could not load the function, shutting down.

From what I realized: the build in the dist is different between the two versions:

Nx Report (17.0.3):

 Node   : 20.9.0
   OS     : darwin-arm64
   npm    : 10.2.4
   
   nx (global)        : 17.0.3
   nx                 : 17.0.3
   @nx/js             : 17.0.3
   @nx/jest           : 17.0.3
   @nx/linter         : 17.0.3
   @nx/eslint         : 17.0.3
   @nx/workspace      : 17.0.3
   @nx/angular        : 17.0.3
   @nx/cypress        : 17.0.3
   @nx/devkit         : 17.0.3
   @nx/esbuild        : 17.0.3
   @nx/eslint-plugin  : 17.0.3
   @nx/nest           : 17.0.3
   @nx/node           : 17.0.3
   @nrwl/tao          : 17.0.3
   @nx/web            : 17.0.3
   @nx/webpack        : 17.0.3
   typescript         : 5.1.6
   ---------------------------------------
   Community plugins:
   @nx-extend/gcp-functions : 10.0.1

Compiled version before update (17.0.3):

/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
(() => {
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CloudFunctions = void 0;
const { foo = 'testBar' } = process.env;
const CloudFunctions = async (req, res) => {
    res.status(200).send(foo);
};
exports.CloudFunctions = CloudFunctions;

})();

var __webpack_export_target__ = exports;
for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
/******/ })()
;
//# sourceMappingURL=main.js.map

Nx Report (17.1.3):

 Node   : 20.9.0
   OS     : darwin-arm64
   npm    : 10.2.4
   
   nx (global)        : 17.1.3
   nx                 : 17.1.3
   @nx/js             : 17.1.3
   @nx/jest           : 17.1.3
   @nx/linter         : 17.1.3
   @nx/eslint         : 17.1.3
   @nx/workspace      : 17.1.3
   @nx/angular        : 17.1.3
   @nx/cypress        : 17.1.3
   @nx/devkit         : 17.1.3
   @nx/esbuild        : 17.1.3
   @nx/eslint-plugin  : 17.1.3
   @nx/nest           : 17.1.3
   @nx/node           : 17.1.3
   @nrwl/tao          : 17.1.3
   @nx/web            : 17.1.3
   @nx/webpack        : 17.1.3
   nx-cloud           : 16.5.2
   typescript         : 5.2.2
   ---------------------------------------
   Community plugins:
   @nx-extend/gcp-functions : 10.0.1

Compiled version after update (17.1.3):

/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
(() => {
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
const { foo = 'testBar' } = process.env;
const CloudFunctions = async (req, res) => {
    res.status(200).send(foo);
};
exports.CloudFunctions = CloudFunctions;

})();

/******/ })()
;
//# sourceMappingURL=main.js.map

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 30 (15 by maintainers)

Most upvoted comments

Nx released the fix (17.2.0)

No worries mate, you’re doing great work - your library saved me a ton of time.

I’ll also find some time to contribute in the upcoming weeks, this is a great project and a great time saver. Thank you

Sorry for all the issues here, I really need to invest some time and finish + update docs (#152).

The issues we encountered here I updated.

Based on the info inside the projects deploy info it will build an endpoint, the runner should also log all the endpoints it registeres.

So each function needs to be added to the map, with map<nx project name, import to main file>. They can than be called like localhost:9000/<functionName>

Sorry for that, just now noticed that when updating the code to the latest runner I did not update the generating of the runner, can you change your json to the following:

{
  "name": "cloud-functions-runner",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "projectType": "application",
  "sourceRoot": "apps/cloud-functions-runner/src",
  "targets": {
    "_build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/cloud-functions-runner",
        "main": "apps/cloud-functions-runner/src/main.ts",
        "tsConfig": "apps/cloud-functions-runner/tsconfig.app.json",
        "compiler": "tsc",
        "target": "node",
        "namedChunks": true
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "options": {
        "buildTarget": "cloud-functions-runner:_build"
      }
    }
  },
  "tags": []
}

Let me know if it works or if you get other issues.

Could you also give it a try typescript: 5.1.6 (same version when the build was still ok)

This one works. The new angular however forces us to use to use >=5.2

Interesting, not sure if we can do something about it here.