Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

ES Modules not working in GCP functions

 

elow has the details , tried multiple updates, still no luck works in VS code but not in gcp - cloud run package.json

{
  "name": "whatsappendpoint-test2",
  "type" : "module",
  "engines": {
    "node": ">=14.0.0"
  },
  "version": "0.0.1",
  "dependencies": {
    "@google-cloud/functions-framework": "^3.0.0"
   
  }
}

Code

export function test(req, res) {
    import {MY_CONST} from './consts.js';
    console.log(test)
    res.send('Hello world');
};

BUILD ERROR

Running "node --check index.js"enter code here
/workspace/index.js:4
import {MY_CONST} from './consts.js'
^
SyntaxError: Unexpected token '{'
at checkSyntax (node:internal/main/check_syntax:74:5)
Node.js v22.14.0
0 0 39
0 REPLIES 0