Allow me to clarify...
I am encountering an issue with my utils.js
file:
import dayjs from 'dayjs'; //https://github.com/iamkun/dayjs
exports.utils = (function() {
someDateFunction() {
...some dayjs function calls ....
}
})();
(Although it has been suggested by someone that it should be module.exports
, I have other source files where both ways work - with or without module
.)
When I include the import statement in the first line, vue-cli compiles without errors. However, when running in the browser, I encounter the following error:
Uncaught ReferenceError: exports is not defined
at eval (utils.js?2f14:3)
at Module../src/assets/js/utils.js (app.js:1541)
at __webpack_require__ (app.js:849)
at fn (app.js:151)
...
I am including/importing this utils.js
file using
const { utils } = require("@/assets/js/utils.js");
Why am I unable to import in the file?
If you require version information, please let me know and guide me on the commands to retrieve the necessary details (running on macos).
I have searched extensively online and found suggestions related to solving it with typescript or vue js.
Unfortunately, none of these solutions seem to work for me. Surely, I am not the first one facing such issues, right? Any assistance would be greatly appreciated.
References:
My dependencies in package.json
"dependencies": {
"axios": "^0.21.1",
"bootstrap": "^4.5.3",
"bootstrap-vue": "^2.18.0",
"core-js": "^3.6.5",
"cropperjs": "^1.5.9",
"dayjs": "^1.9.6",
"vue": "^2.6.12"
},