-
Notifications
You must be signed in to change notification settings - Fork 171
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
ESM 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
jthoward64, abraham, hputzek, tinovyatkin, dimavolo and 3 morejthoward64jthoward64, nosovk and abraham
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working