Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [ERR_REQUIRE_ESM] #5

Open
JErazo7 opened this issue Feb 11, 2024 · 4 comments
Open

Error [ERR_REQUIRE_ESM] #5

JErazo7 opened this issue Feb 11, 2024 · 4 comments

Comments

@JErazo7
Copy link

JErazo7 commented Feb 11, 2024

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
Copy link

xavy26 commented Mar 4, 2024

@JErazo7 tal vez lo solucionaste?

@rsbmk
Copy link

rsbmk commented May 20, 2024

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

@rsbmk
Copy link

rsbmk commented May 26, 2024

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
Copy link
Author

JErazo7 commented May 26, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants