Open
Conversation
### Title: Encourage Explicit Import Paths for Better Compatibility and Predictability **Description:** When using Alpine.js via a CDN (e.g., [jsDelivr](https://cdn.jsdelivr.net)), importing modules without explicit file extensions may lead to issues. For example, attempting to import the CSP build results in a 404 error: ```javascript import Alpine from 'https://cdn.jsdelivr.net/npm/@alpinejs/csp@3.14.9/builds/cdn.js'; ``` This error occurs because Alpine.js includes module imports without explicitly specifying file extensions. Some runtime environments and CDNs, including Deno, enforce stricter module resolution and do not guess the correct extension. ### Example Error: ``` GET https://cdn.jsdelivr.net/npm/@alpinejs/csp@3.14.9/src/index net::ERR_ABORTED 404 (Not Found) ``` ### Suggested Solution: - Explicitly specify `.js` in all import paths, e.g.: ```javascript import Alpine from './index.js'; ``` - This approach is aligned with best practices and ensures compatibility across multiple environments. Ryan dhal did regreted the hole module resolver thinking index was cute, but oh so wrong he was. it adds complexity to a simple solution that don't even work in the browser/esm. It gets harder to make the switch by refactoring code to esm. paths need to be guessed/looked up: did you meant to import `foo.js` or `foo/index.js`? Remote path resolver don't have this luxury where it dose not have direct access to the harddrive and can't lookup the file that is needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
use explicit path in imports (See #4587)