Опишите ошибку: Я использую Google Cloud Run для запуска моего приложения svelte kit с адаптером узла. Кажется, он работает с версией по умолчанию, но с моим пользовательским доменом он не может загружать ресурсы в маршрутах [slug] .svelte.
Версия по умолчанию:
https://youernes-22w6ta6irq-ew.a.run.app/yhoyquetoca
https://youernes-22w6ta6irq-ew.a.run.app/planes/UEVytEBG6rfcLrdqflD8TsjmCRn2_1611080173358
Версия пользовательского домена:
https://youernes.com/yhoyquetoca
https://youernes.com/planes/UEVytEBG6rfcLrdqflD8TsjmCRn2_1602059251917
В версии пользовательского домена я не могу получить доступ к информации, хотя он может получать данные из модуля сценария.
Я использую адаптер узла, и это моя следующая конфигурация:
const sveltePreprocess = require("svelte-preprocess");
const node = require('@sveltejs/adapter-node');
const pkg = require('./package.json');
/** @type {import('@sveltejs/kit').Config} */
module.exports = {
preprocess: [
sveltePreprocess({
defaults: {
style: "postcss",
},
postcss: true
}),
],
kit: {
hostHeader: 'X-Forwarded-Host',
// By default, `npm run build` will create a standard Node app.
// You can create optimized builds for different platforms by
// specifying a different adapter
adapter: node(),
// hydrate the <div id = "svelte"> element in src/app.html
target: '#svelte',
vite: {
ssr: {
noExternal: Object.keys(pkg.dependencies || {})
}
}
}
};
1-й я бегу npm запустить сборку
а также 2-й я использую докер
FROM node:12.17
WORKDIR /youernes
ENV PORT=8080
ENV HOST=0.0.0.0
COPY . .
CMD [ "node" , "build/" ]
Когда я открываю папку с самолетами, я получаю следующие ошибки:
GET https://youernes.com/_app/pages/planes/[slug].svelte-098e0796.js net::ERR_ABORTED 404
GET https://youernes.com/_app/assets/pages/planes/[slug].svelte-377bb070.css net::ERR_ABORTED 404
Failed to fetch dynamically imported module: https://youernes.com/_app/pages/planes/[slug].svelte-098e0796.js
TypeError: Failed to fetch dynamically imported module: https://youernes.com/_app/pages/planes/[slug].svelte-098e0796.js
Как воспроизвести проблему, чтобы получить решение: Вы должны реализовать с адаптером узла один проект svelte kit с маршрутами [slug] .svelte, а затем реализовать его с помощью Google Cloud Run с пользовательским доменом. Может ли кто-нибудь мне помочь или хотя бы пробовал это?
Большое спасибо всем.
Это запись в журнале о неудавшемся запросе:
{
"insertId": "6066e02400082881b572b208",
"httpRequest": {
"requestMethod": "GET",
"requestUrl": "https://youernes-22w6ta6irq-ew.a.run.app/_app/assets/pages/planes/%5Bslug%5D.svelte-377bb070.css",
"requestSize": "1328",
"status": 404,
"responseSize": "2456",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:86.0) Gecko/20100101 Firefox/86.0",
"remoteIp": "66.249.83.222",
"referer": "https://youernes.com/planes/UEVytEBG6rfcLrdqflD8TsjmCRn2_1593543470756",
"serverIp": "216.239.36.53",
"latency": "0.011769378s",
"protocol": "HTTP/1.1"
},
"resource": {
"type": "cloud_run_revision",
"labels": {
"revision_name": "youernes-00113-fig",
"project_id": "youernes-87323",
"location": "europe-west1",
"service_name": "youernes",
"configuration_name": "youernes"
}
},
"timestamp": "2021-04-02T09:13:08.534657Z",
"severity": "WARNING",
"labels": {
"instanceId": "00bf4bf02de904ce6cf09f7cd67bf18ee67e031ee0ac73713f20ab6a480da8c62529932f804ba2674179172182f7ad2195ed59bc668374b9f4685f9a51b7346b282c41672b"
},
"logName": "projects/youernes-87323/logs/run.googleapis.com%2Frequests",
"trace": "projects/youernes-87323/traces/781ee7c4e577db5b65e49db593fe58e5",
"receiveTimestamp": "2021-04-02T09:13:08.549948513Z"
}
Кстати: Я создаю сборку приложения sveltekit на своем локальном компьютере, потому что если я хочу создать проект с помощью докера в контейнере облачного запуска, я получаю ошибки:
FROM node:12.17.0
WORKDIR /youernes
ENV PORT=8080
ENV HOST=0.0.0.0
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD [ "node" , "build/" ]
#10 0.864 #10 0.864 > [email protected] build /youernes #10 0.864 > svelte-kit build #10 0.864 #10 0.917 (node:18) ExperimentalWarning: The ESM module loader is experimental. #10 1.352 vite v2.1.5 building for production... #10 1.676 transforming... #10 23.59 ✓ 52 modules transformed. #10 23.93 /youernes/node_modules/esbuild/bin/esbuild: 1: /youernes/node_modules/esbuild/bin/esbuild: Syntax error: word unexpected (expecting ")") #10 23.98 [vite:esbuild-transpile] Cannot call write after a stream was destroyed #10 23.98 > Cannot call write after a stream was destroyed #10 23.98 Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed #10 23.98 at doWrite (_stream_writable.js:399:19) #10 23.98 at writeOrBuffer (_stream_writable.js:387:5) #10 23.98 at Socket.Writable.write (_stream_writable.js:318:11) #10 23.98 at Object.writeToStdin (/youernes/node_modules/esbuild/lib/main.js:1413:19) #10 23.98 at sendRequest (/youernes/node_modules/esbuild/lib/main.js:576:14) #10 23.98 at start (/youernes/node_modules/esbuild/lib/main.js:1104:13) #10 23.98 at Object.transform (/youernes/node_modules/esbuild/lib/main.js:1114:9) #10 23.98 at /youernes/node_modules/esbuild/lib/main.js:1465:55 #10 23.98 at new Promise () #10 23.98 at Object.transform (/youernes/node_modules/esbuild/lib/main.js:1465:14) #10 24.06 npm ERR! code ELIFECYCLE #10 24.06 npm ERR! errno 1 #10 24.07 npm ERR! [email protected] build:
svelte-kit build
#10 24.07 npm ERR! Exit status 1 #10 24.07 npm ERR! #10 24.07 npm ERR! Failed at the [email protected] build script. #10 24.07 npm ERR! This is probably not a problem with npm. There is likely additional logging output above. #10 24.08 #10 24.08 npm ERR! A complete log of this run can be found in: #10 24.08 npm ERR! /root/.npm/_logs/2021-04-02T09_06_13_694Z-debug.log ------ executor failed running [/bin/sh -c npm run build]: exit code: 1
Наконец, я решил проблему, сопоставив пользовательские домены с Google Cloud Run ?
Попробуйте сначала выполнить "npm install" на образе сборки? У вас есть запись в журнале из вашего докера, что обслуживает "node build /"?