miguelangarano / open-factura

MIT License
37 stars 16 forks source link

Error [ERR_REQUIRE_ESM] #5

Open JErazo7 opened 4 months ago

JErazo7 commented 4 months ago

Hola Miguel, te comento que estoy tratando de usar tu paquete, pero obtengo el siguiente error al tratar de compilar mi cloud function:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/open-factura/node_modules/node-fetch/src/index.js from /Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/open-factura/dist/index.js not supported.
Instead change the require of /Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/open-factura/node_modules/node-fetch/src/index.js in /Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/open-factura/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/open-factura/dist/index.js:168:33)
    at Object.<anonymous> (/Users/josueerazo/Repositories/agro_tracker/firebase/functions/lib/index.js:8:24)
    at async loadModule (/Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/firebase-functions/lib/runtime/loader.js:48:20)
    at async loadStack (/Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/firebase-functions/lib/runtime/loader.js:93:17)
    at async /Users/josueerazo/Repositories/agro_tracker/firebase/functions/node_modules/firebase-functions/lib/bin/firebase-functions.js:56:27 {
  code: 'ERR_REQUIRE_ESM'

En mi proyecto, mi tsconfig.json se ve de la siguiente manera:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

y mi package.json:

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "build: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": "18"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^11.8.0",
    "firebase-functions": "^4.3.1",
    "open-factura": "^0.1.1"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.12.0",
    "@typescript-eslint/parser": "^5.12.0",
    "eslint": "^8.9.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.25.4",
    "firebase-functions-test": "^3.1.0",
    "typescript": "^5.3.3"
  },
  "private": true
}

Tienes alguna idea de como puedo solucionarlo?

xavy26 commented 4 months ago

@JErazo7 tal vez lo solucionaste?

rsbmk commented 1 month ago

tengo el mismo problema, creo que por eso la gente le hace fork

rsbmk commented 1 month ago

El error es la librería de node-fetch que solo soporta lo commonjs. Acabo de mandar un pr eliminando esta librería. Porque después de node 18 ya incluye fetch nativo

JErazo7 commented 1 month ago

El error es la librería de node-fetch que solo soporta lo commonjs. Acabo de mandar un pr eliminando esta librería. Porque después de node 18 ya incluye fetch nativo

@rsbmk podrías por favor adjuntar el PR?