【问题标题】:Can't read file included as a script in angular.json无法读取作为脚本包含在 angular.json 中的文件
【发布时间】:2022-12-03 04:37:15
【问题描述】:

我试图在我的 Angular 项目中包含 Google Maps 集群脚本。我已经尝试了所有常见的建议,例如添加一个<script>链接到index.html,但到目前为止,没有任何效果。

当我尝试包含时收到令人困惑的错误消息

https://unpkg.com/@googlemaps/markerclustererplus/dist/index.min.js

作为angular.json 文件中的脚本。根据错误输出,

发生未处理的异常:脚本文件 https://unpkg.com/@googlemaps/markerclustererplus/dist/index.min.js 不存在。

尽管该文件确实存在:可以单击该链接来验证这一点。

根据我的阅读,angular.json 中的 scripts 元素应该能够包含这样的外部脚本。这里可能出了什么问题?是否有需要更改的设置?

【问题讨论】:

  • 当 webpack 生成 bundle 时,它​​不会发出任何 http 请求,它只是从项目文件夹中收集文件。因此,您应该将此脚本添加到您的项目中,而不是 url,并提供它的路径
  • 这已经成功了。如果您将其添加为答案,我会投赞成票。

标签: angular google-maps google-maps-markers


【解决方案1】:

将它添加到你的 index.html

    <script src="https://unpkg.com/@googlemaps/markerclustererplus/dist/index.min.js"></script>

它会起作用的。

【讨论】:

    猜你喜欢
    • 2020-04-12
    • 2010-10-13
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 2012-01-12
    • 2011-08-28
    • 1970-01-01
    相关资源
    最近更新 更多