I have a good understanding of component registration, but I am encountering a challenging issue:
- Vue.js component Unknown custom element
- Unknown custom element when nesting components in Vue.js
The Issue at Hand
While using the development server, I am facing an inconsistent "Unknown Custom Element" problem within a specific component (now affecting multiple components). This seems to occur only after reloading the page and can be resolved temporarily by triggering a hot module reload (HMR), such as making changes in the template and saving the file.
- Component:
PropertyEditForm
- Imported Component:
ViewEditChip
ViewEditChip
is functioning well in other components- I'm assigning the component as expected in
PropertyEditForm
(TypeScript)components: {'view-edit-chip': ViewEditChip}
- This issue disappears with HMR, but reappears after app reload
Error Message:
Unknown custom element: - Have you registered the component correctly? For recursive components, ensure to provide the "name" option.
Code Snippets
Note: This code is in TypeScript using class-component syntax
ViewEditChip
declaration:
@Component({name: 'view-edit-chip'})
PropertyEditForm
declaration:
@Component({
name: 'property-edit-form',
components: {
'view-edit-chip': ViewEditChip
}
})
PropertyEditForm
template usage:
<view-edit-chip :item.sync="item"></view-edit-chip>
Thoughts on the Matter
- Uncertain if this issue pertains to where or how it's being used?
- Doubtful that the
ViewEditChip
itself or its import are causing the trouble since they work fine in other instances.- In fact, most of the structure of
PropertyEditForm
is copied from other functional components
- In fact, most of the structure of
- Possibly a webpack-related problem?
Additional Insights
This issue is appearing more frequently with various components in my application. The cause is unknown, and there is no reproducible scenario. These errors surface only on a full site reload and are corrected with an HMR. They may or may not occur with the same components depending on their location within the app, which seems arbitrary to me.
For example, I have components like FileSystemTree
, FileSystemToolbar
, & FileSystemMainView
. When used in a view called FileSystemView
, they function correctly. However, creating a FileSystem
component in the same directory as the above three triggers the error, even if the code is identical to FileSystemView
.
Attempted Workaround Example
If I move FileSystem
up one directory and adjust the imports to point to the subdirectory (which has an index.ts
), the issue disappears. But relocating it back to the original directory brings back the problem.