Use import in firebase cloud functions

Viewed 823

I'm trying to run firebase cloud functions with "serve": "firebase emulators:start --only functions" on my local machine which has node version 12.
I cannot use .mjs extension because if I use .mjs firebase wont recognize it and gives me this error:

Error: Cannot find module '/home/rumesh/IdeaProjects/firebaseapp/functions'

Cannot use "type":module in package.json gives me this error:

require() of ES modules is not supported.
require() of /home/rumesh/IdeaProjects/firebaseapp/functions/index.js from /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/rumesh/IdeaProjects/firebaseapp/functions/package.json. 

How can I use import statements without using require statements in this scenario?

0 Answers
Related