I'm not sure what I'm missing here. I'm working on a project using jspm and es6-module-loader. I've got an module defined as follows:
import hooks from './hooks';
import api from './api';
import tools from './tools';
const StencilUtils = {
hooks: hooks,
api: api,
tools: tools,
};
export {hooks, api, tools};
export default StencilUtils;
/* global define */
(function(root) {
if (typeof define === 'function' && define.amd) {
define(function() {
return (root.stencilUtils = StencilUtils);
});
} else if (typeof module === 'object' && module.exports) {
module.exports = StencilUtils;
} else {
window.stencilUtils = StencilUtils;
}
}(this));
I'm importing this module in another file, and using it like so:
import utils from 'bigcommerce/stencil-utils';
utils.hooks.on('cart-item-add', (event, form) => {
// do stuff
});
When the files load, I get an error that utils
is undefined
. If I change the file to this:
import {hooks} from 'bigcommerce/stencil-utils';
hooks.on('cart-item-add', (event, form) => {
// do stuff
});
It works correctly. So, it appears something is not working correctly with the default export statement. Is there something obviously wrong here with the import or export statements that would cause this issue?
import utils
line and the variable is undefined. I am really confused why that is happening. – Antipyrinestencil-utils
and the file that imports it (where you get the error), so that's a good place to start. If you still don't get anything, you could add aconsole.log("initialising "+__filename)
to every single file, so you can check the log which modules have been loaded and which not when you get the exception. – Infer