I published an npm package. The directory structure is something like the following:
my-package
└── js/script.js
└── index.js
The js/script.js
file contains an object that is the name of my library, lets say elephant
. Something like this:
var elephant = {
function_1: function() {
...
},
function_2: function() {
...
}
}
In my index.js
file, I am exporting this like so:
import { elephant } from "./js/script.js";
export default elephant;
Once I published and installed my package, I tried to use it in my project using the following lines of code:
const elephant = require('my-package');
elephant.function_1();
elephant.function_2();
However, unfortunately when I run my dev server (in a Vue project), I get the following error:
"TypeError: elephant.function_1 is not a function"
What am I doing wrong? The function has been clearly defined, and the export works, but the function is not detected. Any help is appreciated. Thanks.