【问题标题】:Angular ng build --prod, output index.html produces nothingAngular ng build --prod,输出 index.html 什么也没产生
【发布时间】:2020-04-19 18:37:34
【问题描述】:

我看过一些教程,在运行 ng build --prod 之后,他们可以进入 dist 文件夹并从那里运行 index.html。但是当我这样做时,什么也没有发生。我可以在上面添加一个 p 标签,它会显示出来,那为什么 app-root 不显示呢?

控制台输出:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///runtime-es2015.1eba213af0b233498d9d.js. (Reason: CORS request not http).

【问题讨论】:

  • 是否为其他静态文件提供服务?您是否看到它们被加载到网络选项卡中?控制台有错误吗?
  • 跨域请求被阻止:同源策略不允许读取位于 file:///runtime-es2015.1eba213af0b233498d9d.js 的远程资源。 (原因:CORS 请求不是 http)。

标签: angular build


【解决方案1】:

您需要使用HTTP 超文本传输​​协议而不是文件打开index.html,所以我建议您使用http-server npm install http-server -g 然后运行 ​​http-server dist

【讨论】:

    猜你喜欢
    • 2019-11-29
    • 2022-07-20
    • 2018-06-30
    • 1970-01-01
    • 2019-02-28
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    相关资源
    最近更新 更多