JavaScript SyntaxError: Cannot use import statement outside a module - Solution & Explanation
This error occurs when you try to use an import statement outside of a module. In JavaScript, a module is a file that contains code that can be imported and exported to other modules.
To fix this error, make sure you are using an import statement inside a module. This means that your code should be in a file that has the '.js' extension and has been designated as a module using the 'type=module' attribute in the script tag.
For example, if you have a file named 'module.js' that contains some code you want to import in another file, make sure that you have the following line at the top of the file:
<script type='module' src='module.js'></script>
Then, in the file where you want to import the code from 'module.js', use the following syntax:
import { someFunction } from './module.js';
This will import the 'someFunction' function from the 'module.js' file. Make sure that the file path is correct and that the module has been exported correctly.
原文地址: https://www.cveoy.top/t/topic/oNer 著作权归作者所有。请勿转载和采集!