ESM support stopped working in Cloud Functions (GCF)
See original GitHub issueESM support stopped working today in Google Cloud Functions (GCF) environment with Node.js 16 runtime. Trying to deploy an ESM codebase fails with the error:
To load an ES module, set "type": "module" in the package.
package.json
{
"name": "esm",
"type": "module",
"exports": "./index.js",
"packageManager": "yarn@3.2.0-rc.12"
}
index.js
export function esm(req, res) {
res.send("PASS");
}
$ cloud functions deploy esm \
--project=example --region=us-central1 --allow-unauthenticated --trigger-http \
--entry-point=esm --memory=256MB --runtime=nodejs16 --source=. \
--set-env-vars="NODE_OPTIONS=--loader=./.pnp.loader.mjs --require=./.pnp.cjs --no-warnings"
Workaround (if you want to preserve ESM in your project)
- Bundle the code. E.g. by using Rollup and Babel wtih
@babel-preset/env
,target: { node: "14" }
preset - Deploy to Node.js v14 GCF runtime. See example: GraphQL API and Relay Starter Kit →
api/rollup.config.js
Ref #233, #292, https://github.com/nodejs/node/issues/41189, https://github.com/nodejs/node/pull/41198
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:28 (13 by maintainers)
Top Results From Across the Web
Running Functions with Function Frameworks - Google Cloud
Once you're finished running your function, stop the running framework instance by pressing CTRL-C . Was this helpful? Send feedback.
Read more >Can't use ES modules in Google Cloud Functions
Google Cloud Functions (and therefore Firebase Functions) does not support ESM modules yet:.
Read more >Getting started with Cloud Functions (2nd gen)
In this codelab, you will learn about Google Cloud Functions (2nd gen). More specifically, you will deploy functions that respond to HTTP ...
Read more >ES Modules in Cloud Functions - Medium
ES modules (aka ECMAScript modules or ESM) are a TC39 standard, ... With recent updates, Google Cloud Functions for Node now supports ES ......
Read more >graphql-upload-minimal - npm
Google Cloud Functions (GCF) Experimental. Untested. Azure Functions Working. Koa · Express.js. See also GraphQL multipart request spec server ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This appears to be a regression in v16 of the Node.js engine. I have filed https://github.com/nodejs/node/issues/41189. Unfortunately, the work around is to use
nodejs14
on GCF for now.The rollout completed a few hours ago. I just confirmed that I can deploy an ESM function in
europe-west1
with thenodejs16
runtime. Please re-open the bug if you are still having issues.