Can ES2015 Import Work in Firefox?
Despite placing your import statement at the top level of your t1.js file, you encounter the error: "SyntaxError: import declarations may only appear at top level of a module." This suggests that Firefox may not be fully supporting ES2015 import functionality.
Understanding the Correct Top-Level Requirement
While your import statement is located at the beginning of t1.js, it is crucial to note that the file itself must explicitly indicate that it's loaded as a module. Simply placing the import statement at the top of a non-module file will not suffice.
How to Enable Module Loading in Firefox
To resolve the issue, you need to add the "type" attribute to your script tag, specifying that it's a module:
<code class="html"><script src="t1.js" type="module"></script></code>
Browser Compatibility
ES2015 import/export functionality is currently fully supported in the following browser versions and later (check caniuse.com for the most up-to-date list):
Enabling Module Support in Older Browsers
For older browser versions, you may need to enable certain flags:
The above is the detailed content of Why Does Firefox Not Support ES2015 Imports?. For more information, please follow other related articles on the PHP Chinese website!