<script type = 'module' >
import {title} from './hd.js'
</script>
Hd.js文件引入路径没有问题
let title = ‘后盾人’;
export {title}
报错
Access to script at
‘file:///D:/%E5%AD%A6%E4%B9%A0/%E6%B5%B7%E8%B1%9A%E6%97%A5%E8%AE%B0%20javascript/%E6%A8%A1%E5%9D%97%E5%8C%96%E5%BC%80%E5%8F%91/hd.js’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
hd.js:1 Failed to load resource: net::ERR_FAILED
模块的基本使用.html:1 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: file:///D:/%E5%AD%A6%E4%B9%A0/%E6%B5%B7%E8%B1%9A%E6%97%A5%E8%AE%B0%20javascript/%E6%A8%A1%E5%9D%97%E5%8C%96%E5%BC%80%E5%8F%91/hd.js
解决方式
解决办法 VScode 前端(html文件)以服务器模式打开