I’ve been struggling with a very odd bug(?) with regards to importing an API module into a nested component in a Vue app.
This is the simplest I could reduce the issue down to.
DogsCreate component renders the
CreateDogsModal, which is importing the
dogs module from the API directory.
As you can see, the codesandbox errors out even on the base URL with the error
Cannot read property 'default' of undefined. If running this code locally not on codesandbox, the base URL renders ok, but if you go to
/dogs/create, the error then becomes
Failed to resolve component: CreateDogsModal.
The things I’ve found that fix this are:
- Commenting out the API import statement in
CreateDogsModal(not an option for us, we need to be able to create and import API modules)
- Commenting out the
main.js(…also not an option for us)
- Importing the
App.vuewith a relative import or
@/components/TopNav.vueworks fine, but strangely importing
DogsCreate.vuewith a relative import or
@/components/[component-name].vuedoes not. Also, the latter would be somewhat acceptable as a long-term solution, but I’d prefer the
@/componentsshorthand and that still leaves the root cause undetermined.
I’m using the default
vue-cli webpack configuration and have checked via
vue inspect that the alias seems to be set properly.
I’ve been spinning my wheels for a week trying to figure this out and just…cannot. Does anyone have any ideas for what may be happening?