Closed jordanebelanger closed 2 years ago
@jordanebelanger this was an intentional change. index.js
now exposes a public API for registering functions declaratively with the functions framework. We separated out the logic for spinning up the server to make it possible to consume the API in scenarios where you may not want to start the server (e.g. in unit tests).
If I understand what you are trying to do correctly, I suggest you invoke our bin
scripts instead of relying on them being the same as our main
. When you npm install
the functions framework, the executables are automatically symlinked into ./node_modules/.bin
so you could use them in an npm start script like:
"start": "node -r dotenv/config ./node_modules/.bin/functions-framework --source=build/src/ --target=entryPoint --signature-type=event"
I expect this to be much more robust because we are very unlikely to change the name of our bin
executables (they are part of our public API). The name of the files they point to is a private implementation detail that is subject to change at any time.
This applies to 2.0.0 specifically.
In package.json, the
main
field is currentlyindex.js
, despiteindex.js
no longer being an entry point of the functions-framework program (it's nowmain.js
since v2.0.0).What this means in practice is a package.json script like below now exits without starting the test server:
"start": "node -r dotenv/config node_modules/@google-cloud/functions-framework --source=build/src/ --target=entryPoint --signature-type=event"
This can be fixed by changing the above to:
"start": "node -r dotenv/config node_modules/@google-cloud/functions-framework/build/src/main.js --source=build/src/ --target=entryPoint --signature-type=event"
I cannot say if this change is on purpose or not but based on many answers regarding the loading of env variables before running the functions-framework, this will probably be a breaking change for quite a few people who were relying on the
main
field of package.json being an entry point to the test server.