Creator3打包WebMobile 报错 Access to script at ‘chunks:///_virtual/xxxxx.ts‘ has been blocked by CORS

前言

Access to script at 'chunks:///_virtual/xxxxxxx.ts' from origin 'http://xxxxx:7456' 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.

网上几乎没有这个报错的资料,相信很多人遇到了也是一脸懵逼。能查到的资料和cocos creator几乎无关。

分析

基本能看出,是某些文件,未能打包进入最终的包体导致的。

查看错误日志,可以发现,这些文件名是最近新加的功能,类似于编辑器使用,但是不需要在最终工程里面。

而这些文件,也是处于单独的文件夹,并不会被打入主包,或者子包bundles里。

解决方案一

给这些代码开一个bundles,确保会成一个独立的子包(除了代码不要包含其他文件,比如预制体prefab)

因此代码量小,而且没有单独的逻辑去加载,所以并不影响实际运行。

暴力一点,也可以把代码直接扔到主包里面去。

此方案包体会略微变大。

解决方案二

洁癖的做法,

写脚本,将在最终生成的文件里,删除这些试图加载特殊ts的函数。

找到build/web-mobile/assets/main/index.xxxxxx.js

注意xxxxx每次不一样(勾选了md5)所以这个脚本,还得智能一点。

然后脚本在此文件里

找到

System.register("chunks:///_virtual/xxxxx.ts",

....

});

注意xxxx就是需要删除的类,这一段全部删除

然后找到这一段

System.register("chunks:///_virtual/main", ['./xxxxx.ts',

....

});

将对应的类名删除。

注意不是删除所有,仅删除需要的几个  './xxxx.ts'

以上内容可以通过正则匹配来查找对应的代码,进行删除。

然后重新一跑,就ok了。

root@in_dev_docker:/apollo# bash scripts/msf_create_lossless_map.sh /apollo/hdmap/pcd_apollo/ 50 /apollo/hdmap/ /apollo/bazel-bin WARNING: Logging before InitGoogleLogging() is written to STDERR E0715 22:08:35.399576 6436 lossless_map_creator.cc:162] num_trials = 1 Pcd folders are as follows: /apollo/hdmap/pcd_apollo/ Resolution: 0.125 Dataset: /apollo/hdmap/pcd_apollo Dataset: /apollo/hdmap/pcd_apollo/ Loaded the map configuration from: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. E0715 22:08:35.767315 6436 lossless_map_creator.cc:264] ieout_poses = 1706 Failed to find match for field 'intensity'. Failed to find match for field 'timestamp'. E0715 22:08:35.769896 6436 velodyne_utility.cc:46] Un-organized-point-cloud E0715 22:08:35.781770 6436 lossless_map_creator.cc:275] Loaded 245443D Points at Trial: 0 Frame: 0. F0715 22:08:35.781791 6436 base_map_node_index.cc:101] Check failed: false *** Check failure stack trace: *** scripts/msf_create_lossless_map.sh: line 11: 6436 Aborted (core dumped) $APOLLO_BIN_PREFIX/modules/localization/msf/local_tool/map_creation/lossless_map_creator --use_plane_inliers_only true --pcd_folders $1 --pose_files $2 --map_folder $IN_FOLDER --zone_id $ZONE_ID --coordinate_type UTM --map_resolution_type single root@in_dev_docker:/apollo# bash scripts/msf_create_lossless_map.sh /apollo/hdmap/pcd_apollo/ 50 /apollo/hdmap/
07-16
根据提供的信息,执行脚本 `scripts/msf_create_lossless_map.sh` 时出现了错误。具体的错误信息如: ``` E0715 22:08:35.399576 6436 lossless_map_creator.cc:162] num_trials = 1 Pcd folders are as follows: /apollo/hdmap/pcd_apollo/ Resolution: 0.125 Dataset: /apollo/hdmap/pcd_apollo Dataset: /apollo/hdmap/pcd_apollo/ Loaded the map configuration from: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. E0715 22:08:35.767315 6436 lossless_map_creator.cc:264] ieout_poses = 1706 Failed to find match for field 'intensity'. Failed to find match for field 'timestamp'. E0715 22:08:35.769896 6436 velodyne_utility.cc:46] Un-organized-point-cloud E0715 22:08:35.781770 6436 lossless_map_creator.cc:275] Loaded 245443D Points at Trial: 0 Frame: 0. F0715 22:08:35.781791 6436 base_map_node_index.cc:101] Check failed: false *** Check failure stack trace: *** scripts/msf_create_lossless_map.sh: line 11: 6436 Aborted (core dumped) $APOLLO_BIN_PREFIX/modules/localization/msf/local_tool/map_creation/lossless_map_creator --use_plane_inliers_only true --pcd_folders $1 --pose_files $2 --map_folder $IN_FOLDER --zone_id $ZONE_ID --coordinate_type UTM --map_resolution_type single ``` 这段错误信息表明在执行脚本时发生了一个检查失败的情况。错误的具体位置在 `base_map_node_index.cc:101`。可能的原因包括: 1. 数据不匹配:脚本中使用的数据可能存在不匹配的情况,例如字段名或者数据格式不正确。 2. 数据文件缺失:脚本所需的某些数据文件可能不存在或者路径不正确。 3. 依赖问题:脚本所依赖的某些组件或库可能缺失或者版本不兼容。 请检查脚本 `scripts/msf_create_lossless_map.sh` 中的相关代码,确保数据文件和依赖项的正确性。如果问题仍然存在,您可以提供更多的上下文信息,以便我们能够更好地帮助您解决问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值