It was working before but after updating it gives this error I don't understand what am I doing wrong?
package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"lint:fix": "eslint --fix --ext .js,.jsx .",
"build": "tsc",
"watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/video-intelligence": "^4.1.1",
"@sendgrid/mail": "^7.7.0",
"agora-access-token": "^2.0.4",
"camelcase-keys": "^8.0.2",
"firebase-admin": "^11.2.1",
"firebase-functions": "^4.0.2",
"google-auth-library": "^8.7.0",
"googleapis": "^109.0.1",
"lodash": "^4.17.21",
"node-apple-receipt-verify": "^1.12.1"
},
"devDependencies": {
"@types/node-apple-receipt-verify": "^1.7.1",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.26.0",
"firebase-functions-test": "^3.0.0",
"typescript": "^4.8.4"
},
"private": true
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"compileOnSave": true,
"include": [
"src"
]
}
I used to write like this:
import camelcaseKeys from "camelcase-keys";
Now it started giving this error
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_REQUIRE_ESM]: require() of
ES Module C:\Users\xxx\AndroidStudioProjects\xxx\functions\node_modules\camelcase-keys\index.js from C:\Users\xxx\AndroidStudioProjects\xxx\functions\lib\app-store.purchase-handler.js not supported.
Instead change the require of index.js in C:\Users\xxx\AndroidStudioProjects\xxx\functions\lib\app-store.purchase-handler.js to a dynamic i
mport() which is available in all CommonJS modules.