npm安装anywhere( 随启随用的静态文件服务器),分分钟解决浏览器请求本地js文件跨域问题

以下是一个html文件, chrome浏览器打开该文件;

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="/favicon.ico">
    <meta name="viewport" content="width=600, initial-scale=1.0">
    <title>Vite App</title>
    <script type="module" crossorigin src="/assets/index-GxicIufr.js"></script>
    <link rel="stylesheet" crossorigin href="/assets/index-U9LxSyeS.css">
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

报错如下:

js 复制代码
Access to script at 'file:///Users/***/Documents/code/learning/vue/vue-project/dist/assets/index-GxicIufr.js' 
from origin 'null' has been blocked by CORS policy: 
Cross origin requests are only supported for protocol schemes: 
http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
index.html:8 
 Access to CSS stylesheet at 'file:///Users/shuangguiyu/Documents/code/learning/vue/vue-project/dist/assets/index-U9LxSyeS.css' 
 from origin 'null' has been blocked by CORS policy:
 Cross origin requests are only supported for protocol schemes:
 http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
index.html
        

全局安装anywhere npm install -g anywhere,再前往html文件所在目录执行anywhere -p 8081

Anywhere 随启随用的静态文件服务器。 www.npmjs.com/package/any...

相关推荐
huohaiyu8 小时前
从URL到页面的完整解析流程
前端·网络·chrome·url
阿星AI工作室10 小时前
一个简单Demo彻底理解前后端怎么连的丨Figma + Supabase + Vercel
前端·人工智能
aircrushin10 小时前
一拍即传的平替,完全免费的实时照片墙!
前端
鹏北海12 小时前
JSBridge 原理详解
前端
孟健12 小时前
我的网站被黑了:一天灌入 227 万条垃圾数据,AI 写的代码差点让我社死
前端
anOnion12 小时前
构建无障碍组件之Checkbox pattern
前端·html·交互设计
IT枫斗者14 小时前
IntelliJ IDEA 2025.3史诗级更新:统一发行版+Spring Boot 4支持,这更新太香了!
java·开发语言·前端·javascript·spring boot·后端·intellij-idea
N***p36514 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
享誉霸王15 小时前
15、告别混乱!Vue3复杂项目的规范搭建与基础库封装实战
前端·javascript·vue.js·前端框架·json·firefox·html5
a11177616 小时前
飞机躲避炸弹 网页游戏
前端·开源·html·threejs