I am trying to fix this problem for hours. I’ve read nearly every post about this, but still, I came to no solution.
I am trying to deploy a firebase-function with the “https got-library” dependency, but no matter what I do, nothing works. I am not the best with node-js or typescript (usually a kotlin frontend-dev), so I have no clue what the error wants from me.
Tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": false,
"esModuleInterop": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
],
}
.eslintrc.js
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
],
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"quotes": ["error", "double"],
"import/no-unresolved": 0,
"linebreak-style": ["error", "windows"],
"indent": "off",
"object-curly-spacing": "off",
"no-tabs": 0,
"max-len": "off",
"require-jsdoc": 0,
"no-empty": [0, "allow-empty-functions", "allow-empty-catch"],
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/naming-convention": ["off"],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-var-requires": "off",
"no-mixed-spaces-and-tabs": 0,
"camelcase": 0,
},
};
package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"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": "14"
},
"type": "module",
"main": "lib/index.js",
"dependencies": {
"@google-cloud/functions-framework": "^2.1.0",
"@types/stripe": "^8.0.417",
"firebase-admin": "^10.0.1",
"firebase-functions": "^3.14.1",
"firebase-tools": "^10.0.1",
"form-data": "^4.0.0",
"got": "^12.0.0",
"iso3166-alpha-converter": "^1.0.0",
"mailgun.js": "^4.1.0",
"stripe": "^8.193.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"eslint": "^8.5.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.22.0",
"firebase-functions-test": "^0.3.3",
"typescript": "^4.5.4"
},
"private": true
}
Error
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:UsersImMorDocumentsFirebaseFunctionsfunctions.eslintrc.js
require() of ES modules is not supported.
require() of C:UsersImMorDocumentsFirebaseFunctionsfunctions.eslintrc.js from C:UsersImMorDocumentsFirebaseFunctionsfunctionsnode_modules@eslinteslintrcdisteslintrc.cjs 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 .eslintrc.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:UsersImMorDocumentsFirebaseFunctionsfunctionspackage.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at Object.module.exports [as default] (C:UsersImMorDocumentsFirebaseFunctionsfunctionsnode_modulesimport-freshindex.js:32:59)
at loadJSConfigFile (C:UsersImMorDocumentsFirebaseFunctionsfunctionsnode_modules@eslinteslintrcdisteslintrc.cjs:2531:47)
at loadConfigFile (C:UsersImMorDocumentsFirebaseFunctionsfunctionsnode_modules@eslinteslintrcdisteslintrc.cjs:2615:20)
at ConfigArrayFactory.loadInDirectory (C:UsersImMorDocumentsFirebaseFunctionsfunctionsnode_modules@eslinteslintrcdisteslintrc.cjs:2808:34)
at CascadingConfigArrayFactory._loadConfigInAncestors (C:UsersImMorDocumentsFirebaseFunctionsfunctionsnode_modules@eslinteslintrcdisteslintrc.cjs:3772:46)
at CascadingConfigArrayFactory.getConfigArrayForFile (C:UsersImMorDocumentsFirebaseFunctionsfunctionsnode_modules@eslinteslintrcdisteslintrc.cjs:3693:18)
Function I want to deploy
// THIS IS MAKING THE PROBLEM
import got from "got";
export async function doOnDeletedUser(
// SOME OTHER STUFF
) {
const uid = user.uid;
// SOME OTHER STUFF
}