When working with ESLint, you might encounter an error message that reads: [boundaries]: Please provide element types using the 'boundaries/elements' setting
. This issue typically arises after integrating the plugin:boundaries/recommended
configuration, which is used to enforce architectural boundaries in your codebase. While this plugin is powerful for maintaining a clean architecture, it can be tricky to set up without the correct configuration. In this post, we’ll dive into why this error occurs and walk you through the steps to resolve it. Additional note: this error is related to the eslint-plugin-boundaries package.
Thank me by sharing on Twitter 🙏
Boundaries Error Description:
The exact error message you may encounter is:
[boundaries]: Please provide element types using the 'boundaries/elements' setting
This message appears when you’ve added the plugin:boundaries/recommended
configuration, but haven’t fully specified the element types required by the plugin. ESLint uses these element types to determine and enforce which parts of your project can interact, based on your architectural decisions.
Cause of the Error
The root cause of this error is that the settings.boundaries/elements
configuration is missing or incomplete in your ESLint setup. This setting is crucial because it defines the different architectural layers or modules in your project (e.g., components, services, modules), allowing the boundaries
plugin to enforce rules based on those layers.
Solution
To resolve this error, you need to add the necessary settings.boundaries/elements
configuration to your .eslintrc
file. Here’s a step-by-step guide:
Anker USB to USB C Cable [2 Pack, 3FT], USB A to USB C Charger Cord for Samsung Galaxy S10 S10+, LG V30, Beats Fit Pro and More (USB 2.0, Black)
$8.99 (as of January 22, 2025 11:32 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)USB Type-C to A Cable 5pack 6ft Braided Fast Charging 3A Quick Charger Cord, 6 Foot Compatible iPhone 16/15,Samsung Galaxy S10 S9 S8 Plus, Note 10 9 8, LG V50 V40 G8 G7(Grey)
$9.99 (as of January 22, 2025 11:32 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Anker 332 USB-C Hub (5-in-1) with 4K HDMI Display, 5Gbps - and 2 5Gbps USB-A Data Ports and for MacBook Pro, MacBook Air, Dell XPS, Lenovo Thinkpad, HP Laptops and More
$18.84 (as of January 22, 2025 11:32 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)- Open your ESLint configuration file (usually
.eslintrc
,.eslintrc.json
, or.eslintrc.js
). - Add the following settings under
settings.boundaries/elements
:
"settings": {
"boundaries/elements": [
{ "type": "components", "pattern": "src/components/*" },
{ "type": "services", "pattern": "src/services/*" },
{ "type": "modules", "pattern": "src/modules/*" }
]
}
This example defines three element types: components
, services
, and modules
. Adjust the pattern
field according to the folder structure in your project.
3. Ensure that your ESLint rules align with these element types. For example:
"rules": {
"boundaries/element-types": [
"error", {
"default": "disallow",
"rules": [
{ "from": ["components"], "allow": ["services"] }
]
}
]
}
This configuration specifies which types can interact, based on your architectural boundaries.
4. Save the changes and run ESLint again.
Verification
Once you’ve updated your .eslintrc
configuration, run ESLint in your project. The error [boundaries]: Please provide element types using the 'boundaries/elements' setting
should no longer appear. This indicates that ESLint can now correctly identify the architectural layers and enforce the rules as expected.
Conclusion
Setting up architectural boundaries in a project can significantly enhance code quality and maintainability, but it requires a proper configuration. By defining the necessary element types, you can fully leverage the power of the plugin:boundaries/recommended
configuration without running into errors. The next time you encounter this issue, remember that it’s simply a matter of adding the correct settings.
Tags/Keywords
- ESLint
- module boundaries
- architecture
- JavaScript
- TypeScript
- error handling