good evening, I wanted to ask if someone can help me solve this error I have when creating my own npm library and publishing it. I have it published correctly, but I leave it below.
my package.json that I post the error is:
C:UsersUsuaRIODesktopProyecto-GymApinode_modulessubirimgdist-nodeindex.js:15 upload_up_archive = /*#__PURE__*/function () { ^ ReferenceError: upload_up_archive is not defined at Object.<anonymous> (C:UsersUsuaRIODesktopProyecto-GymApinode_modulessubirimgdist-nodeindex.js:15:19) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Function.Module._load (node:internal/modules/cjs/loader:960:12) at Module.require (node:internal/modules/cjs/loader:1143:19) at require (node:internal/modules/cjs/helpers:121:18) at Object.<anonymous> (C:UsersUsuaRIODesktopProyecto-GymApisrcclientclient.service.ts:24:1) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10
{
"name": "subirimg",
"version": "1.0.6",
"description": "Return cloudinary image",
"keywords": [
"cloudinary",
"Javascript",
"js"
],
"license": "MIT",
"author": "Matias Marcelos Dei Castelli <[email protected]>",
"main": "dist-node/index.js",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"build": "babel src -d dist-node"
},
"dependencies": {
"axios": "^1.6.8",
"cloudinary": "^2.2.0"
},
"devDependencies": {
"@babel/cli": "^7.24.5",
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5"
}
}
import { v2 as cloudinary } from "cloudinary";
const cloudinary_upload = (
cloud_name_cloudinary,
api_key_name_cloudinary,
api_secret_name_cloudinary
) => {
return cloudinary.config({
cloud_name: cloud_name_cloudinary,
api_key: api_key_name_cloudinary,
api_secret: api_secret_name_cloudinary,
});
};
const upload_up_archive = async (
function_cloudinary_value,
archivo,
opciones
) => {
try {
cloudinary_upload(
function_cloudinary_value.cloud_name,
function_cloudinary_value.api_key_name_cloudinary,
function_cloudinary_value.api_secret_name_cloudinary
);
const resultado = await cloudinary.uploader.upload(archivo, opciones);
return resultado;
} catch (error) {
throw new Error("Error al subir el archivo a Cloudinary");
}
};
export default { upload_up_archive };
I also leave the link and git of the library I am creating just in case
https://github.com/MatiasDeiCastelliFL/Subida-Imagen-cloudinary-libreria.git
https://www.npmjs.com/package/subirimg?activeTab=readme
and finally I leave where I want to use the upload function in another project is with nest
import { upload_up_archive } from 'subirimg';
let image: string;
if (file) {
image =
'https://p16-va-default.akamaized.net/img/musically-maliva-obj/1665282759496710~c5_720x720.jpeg';
} else {
const url = await upload_up_archive(
{
cloud_name: process.env.CLOUDINARY_NAME,
api_key_name_cloudinary: process.env.CLOUDINARY_API_KEY,
api_secret_name_cloudinary: process.env.CLOUDINARY_API_SECRET,
},
file,
);
console.log(url);
}
Here I leave my index.js that is inside an src folder
I already have the library installed
Matias Dei Castelli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.