我的应用程序是在StackBlitz中开发的,包括ngx-translate包。在部署到火力基地之前,它运行良好。我尽力详细说明了我的配置和错误日志,因为我自己无法解决。我也通过互联网进行挖掘,但是没有运气解决任何一个问题。抱歉,冗长的帖子。
index.html
<link rel="stylesheet" type="text/css" href="/node_modules/primeicons/primeicons.css" />
<link rel="stylesheet" type="text/css" href="/node_modules/primeng/resources/themes/nova-light/theme.css" />
<link rel="stylesheet" type="text/css" href="/node_modules/primeng/resources/primeng.min.css" />
以上代码错误在Firebase中出现,但在StackBlitz中没有(完美运行)
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://fireforgez.firebaseapp.com/node_modules/primeng/resources/themes/nova-light/theme.css".
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://fireforgez.firebaseapp.com/node_modules/primeng/resources/primeng.min.css".
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://fireforgez.firebaseapp.com/node_modules/primeicons/primeicons.css".
要摆脱它,我做了一个愚蠢的补丁,将其替换为实际的Web URL
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/primeicons.css" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/resources/themes/nova-light/theme.css" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/resources/primeng.min.css" />
PrimeFlex包也遇到类似错误
DevTools failed to load SourceMap: Could not parse content for
https://fireforgez.firebaseapp.com/primeflex.css.map: Unexpected token < in JSON at position 0
我比较了StackBlitz和Firebase,样式表文件都是可加载的。但是,当我替换为firebase托管URL时,所有.css都恢复为firebase主URL例如https://fireforgez.firebaseapp.com/node_modules/primeng/resources/themes/nova-light/theme.css将重定向到https://fireforgez.firebaseapp.com/并产生一系列错误
Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'node_modules/primeng/resources/themes/nova-light/theme.css'
Error: Cannot match any routes. URL Segment: 'node_modules/primeng/resources/themes/nova-light/theme.css'
at ApplyRedirects.noMatchError (router.umd.js:2284) [angular]
at CatchSubscriber.eval [as selector] (router.umd.js:2265) [angular]
at CatchSubscriber.error (catchError.js:48) [angular]
at MapSubscriber.Subscriber._error (Subscriber.js:92) [angular]
at MapSubscriber.Subscriber.error (Subscriber.js:72) [angular]
at MapSubscriber.Subscriber._error (Subscriber.js:92) [angular]
at MapSubscriber.Subscriber.error (Subscriber.js:72) [angular]
at MapSubscriber.Subscriber._error (Subscriber.js:92) [angular]
at MapSubscriber.Subscriber.error (Subscriber.js:72) [angular]
at ThrowIfEmptySubscriber.Subscriber._error (Subscriber.js:92) [angular]
at ThrowIfEmptySubscriber.Subscriber.error (Subscriber.js:72) [angular]
at TakeLastSubscriber.Subscriber._error (Subscriber.js:92) [angular]
at TakeLastSubscriber.Subscriber.error (Subscriber.js:72) [angular]
at MergeMapSubscriber.OuterSubscriber.notifyError (OuterSubscriber.js:26) [angular]
at resolvePromise (zone.js:816) [angular]
at resolvePromise (zone.js:768) [angular]
at eval (zone.js:878) [angular]
at Object.onInvokeTask (core.umd.js:19397) [angular]
at drainMicroTaskQueue (zone.js:591) [<root>]
对于ngx-translate,它也可以在StackBlitz中正常工作,但无法加载语言文件。
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.onLoad (https://fireforgez.firebaseapp.com/turbo_modules/@angular/[email protected]/bundles/common-http.umd.js:1390:55)
at ZoneDelegate.invokeTask (https://fireforgez.firebaseapp.com/turbo_modules/[email protected]/dist/zone.js:411:35)
at Object.onInvokeTask (https://fireforgez.firebaseapp.com/turbo_modules/@angular/[email protected]/bundles/core.umd.js:19397:37)
at ZoneDelegate.invokeTask (https://fireforgez.firebaseapp.com/turbo_modules/[email protected]/dist/zone.js:410:40)
at Zone.runTask (https://fireforgez.firebaseapp.com/turbo_modules/[email protected]/dist/zone.js:178:51)
at ZoneTask.invokeTask [as invoke] (https://fireforgez.firebaseapp.com/turbo_modules/[email protected]/dist/zone.js:493:38)
at invokeTask (https://fireforgez.firebaseapp.com/turbo_modules/[email protected]/dist/zone.js:1633:18)
at XMLHttpRequest.globalZoneAwareCallback (https://fireforgez.firebaseapp.com/turbo_modules/[email protected]/dist/zone.js:1670:25)
...
message: "Http failure during parsing for https://fireforgez.firebaseapp.com/assets/i18n/en.json"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "https://fireforgez.firebaseapp.com/assets/i18n/en.json"
这里是我完整的angular.json文件
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"demo": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/demo",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css",
"node_modules/primeicons/primeicons.css",
"node_modules/primeng/resources/themes/nova-light/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"../node_modules/quill/dist/quill.core.css",
"../node_modules/quill/dist/quill.snow.css",
"node_modules/primeflex/primeflex.css"
],
"scripts": [
"../node_modules/quill/dist/quill.js"
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demo:build"
},
"configurations": {
"production": {
"browserTarget": "demo:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "demo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"styles.css"
],
"scripts": [
"../node_modules/quill/dist/quill.js"
],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "demo"
}
[非常感谢Eric,他是StackBlitz的所有者,非常感谢并耐心地解释说Firebase部署仍处于Beta版(我之前没有意识到!...)https://github.com/stackblitz/core/issues/1254#issuecomment-636860107
我一直在尝试各种可能的方法来解决SB中的部署问题,但是没有运气。在他的建议下,我下定决心,将项目放到本地,然后在本地手动构建损坏的依赖项。之后,我部署到了Firebase,现在一切正常!
因此,暂时来说,如果您有认真的项目并且需要从SB部署到Firebase,我建议您等到部署得到稳定的版本。