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";
module.exports = elephant;
Once I published and installed my package, I tried to pull it in my project using the following line of code:
const elephant = require('my-package');
elephant.function_1();
elephant.function_2();
However, unfortunately when I run my server (in a Vue project), I get the following error:
Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
I assume this is referring to the third line in the index.js file. How can I fix this issue? How do I export my object variable and use it in my node project? Thanks for any help!
var elephant =toexport elephant =in yourscript.js? I'm expecting the code-splitting is failing here... if not, have you tried console.log() all the way up?Module parse failed