使用“ng build --prod”部署我的Angular应用程序后,我尝试打开index.html文件并检查我的Web应用程序。但是在Chrome、Firefox和Edge Web浏览器中都没有显示任何内容。然后我打开控制台并检查是否有任何错误,它会显示6个错误消息。
我应该提到,我的应用程序在 'http://localhost:4200/' 上成功编译并运行。之后,我尝试了另一个 Angular 应用程序(新的),但是在构建后出现了相同类型的错误。
错误:
1)访问 'file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/runtime-es2015.edb2fcf2778e7bf1d426.js' 的脚本被来自 'null' 的 CORS 策略阻止:跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https。
2)GET file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/runtime-es2015.edb2fcf2778e7bf1d426.js net::ERR_FAILED
3)访问 'file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/polyfills-es2015.2987770fde9daa1d8a2e.js' 的脚本被来自 'null' 的 CORS 策略阻止:跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https。
4) 获取 file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/polyfills-es2015.2987770fde9daa1d8a2e.js 失败 net::ERR_FAILED index.html:1
5) 从来自 'null' 的源访问脚本 'file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/main-es2015.69da1b25d5a7a648b825.js' 已被 CORS 策略阻止:跨源请求只支持协议方案:http、data、chrome、chrome-extension、https。 index.html:36
6) 获取 file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/main-es2015.69da1b25d5a7a648b825.js 失败 net::ERR_FAILED
错误:
1)访问 'file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/runtime-es2015.edb2fcf2778e7bf1d426.js' 的脚本被来自 'null' 的 CORS 策略阻止:跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https。
2)GET file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/runtime-es2015.edb2fcf2778e7bf1d426.js net::ERR_FAILED
3)访问 'file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/polyfills-es2015.2987770fde9daa1d8a2e.js' 的脚本被来自 'null' 的 CORS 策略阻止:跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https。
4) 获取 file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/polyfills-es2015.2987770fde9daa1d8a2e.js 失败 net::ERR_FAILED index.html:1
5) 从来自 'null' 的源访问脚本 'file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/main-es2015.69da1b25d5a7a648b825.js' 已被 CORS 策略阻止:跨源请求只支持协议方案:http、data、chrome、chrome-extension、https。 index.html:36
6) 获取 file:///D:/AngularTshirt/module01/moduleapp01/dist/moduleapp01/main-es2015.69da1b25d5a7a648b825.js 失败 net::ERR_FAILED