Я разрабатываю многоплатформенный проект (настольный компьютер, Android, iOS) с использованием Tauri 2 и Nuxt 3, но при запуске на Android я продолжаю встречаться с ошибкой, связанной с WebSocket, подобной этой.
Есть ли какие-либо идеи Это может мне помочь? - Строка 794 - MSG: [VITE] Не удалось подключиться к WebSocket (ошибка: webSocket закрыт без открытия.).
file: http: //tauri.localhost/_nuxt/@vite/client - строка 835 - MSG: [VITE] Ошибка: WebSocket закрыт без открытия.
File: http: //tauri.localhost/_nuxt/@vite/client - строка 835 - msg: [vite] Ошибка: websocket закрыт без открытия.
file: http: //tauri.localhost/_nuxt/@vite/client - Строка 443 - MSG: UNCAUNT (в Обещании) Ошибка: WebSocket закрыт без открытия.
Настройка проекта
tauri config: < /p>
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "nuxt-app",
"version": "0.1.0",
"identifier": "com.nuxt-app.dev",
"build": {
"frontendDist": "../dist",
"beforeDevCommand": "node preload-config.js && npm run dev -- --host",
"beforeBuildCommand": "npm run build",
"devUrl": "http://192.168.100.127:3000"
},
"app": {
"windows": [
{
"title": "nuxt-app",
"width": 1024,
"height": 600,
"resizable": true,
"fullscreen": false,
"devtools": true,
"additionalBrowserArgs": "--disable-web-security"
}
],
"security": {
"csp": "default-src 'self'; connect-src 'self' http://192.168.100.127:3000",
"capabilities": [
"remote-tag-capability"
]
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"android": {
"minSdkVersion": 26,
"versionCode": 1
}
}
}
< /code>
nuxt config < /p>
import UnoCSS from "unocss/vite";
import dns from 'node:dns';
import path from "path";
dns.setDefaultResultOrder("verbatim");
const host = process.env.TAURI_DEV_HOST || 'localhost'
const serverHost = process.env.VITE_HOST || 'localhost'
const port: number = process.env.PORT || 1420;
const devUrl = `http://${serverHost}:${port}`;
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
modules: [
'vuetify-nuxt-module',
'nuxt-echarts',
'nuxt-echarts',
'@unocss/nuxt',
'@nuxt/icon',
'@nuxtjs/google-fonts'
],
googleFonts: {
families: {
Roboto: true,
"Noto+Sans+JP": [400, 700]
},
display: "swap"
},
echarts: {
charts: ['BarChart', 'LineChart', 'PieChart'],
components: ['DatasetComponent', 'GridComponent', 'TooltipComponent'],
},
vuetify: {
moduleOptions: {
},
vuetifyOptions: {
}
},
// Enable SSG
ssr: false,
icon: {
customCollections: [
{
prefix: 'kinjiro-icons',
dir: './assets/kinjiro-icons'
},
],
},
ignore: ['**/src-tauri/**', '**/node_modules/**', '**/dist/**', '**/.git/**', '**/.nuxt/**', '**/.output/**'],
css: ['@/assets/css/global.css', 'vuetify/styles', '@mdi/font/css/materialdesignicons.css'],
devtools: { enabled: false },
sourcemap: {
server: true,
client: true
},
app: {
head: {
title: 'Nuxt Tauri App',
meta: [
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }
],
script: [
]
}
},
nitro: {
prerender: {
routes: [],
crawlLinks: false
},
preset: 'static',
devProxy: {
"/_nuxt/": {
target: devUrl, // Ensure the right port
changeOrigin: true,
prependPath: false,
ws: true
},
'/api': {
target: devUrl, // Thay bằng URL của backend
changeOrigin: true,
prependPath: false,
}
},
routeRules: {
'/_nuxt/**': { proxy: 'http://192.168.100.127:3000/**', cors: true }
},
experimental: {
nodeFetchCompat: true
}
},
routeRules: {
"/api/**": {
cors: true,
},
"/_nuxt/**": {
cors: true,
},
},
build: {
transpile: ["@tauri-apps/api", 'vuetify'], // Đảm bảo module của Tauri được bundle chính xác
},
devServer: {
host: "0.0.0.0", // Để chấp nhận kết nối từ mạng LAN
port: 3000
},
vite: {
plugins: [UnoCSS()],
esbuild: {
tsconfigRaw: {},
},
define: {
'process.DEBUG': true,
'import.meta.dev': false
},
ssr: {
external: ['@tauri-apps/api']
},
build: {
target: "esnext", // Hoặc thử "es2015" nếu vẫn lỗi
emptyOutDir: false
},
resolve: {
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue", ".css"],
alias: {
"@": path.resolve(__dirname, "./"),
"node_modules": path.resolve(__dirname, "./node_modules"),
},
},
clearScreen: false,
envPrefix: ['VITE_', 'TAURI_'],
server: {
ws: false,
strictPort: true,
cors: {
origin: '*',
methods: ['GET', 'POST'],
allowedHeaders: 'Content-Type Authorization'
},
hmr: {
protocol: 'ws',
host: 'tauri.localhost',
clientPort: port,
port: 3000
// server: { host: 'localhost', protocol: 'ws' }
},
watch: {
usePolling: true
},
// proxy: {
// '/api': {
// target: 'http://192.168.100.127:3000',
// changeOrigin: true,
// secure: false,
// }
// }
}
},
runtimeConfig: {
public: {
apiBase: devUrl
}
},
hooks: {
'vite:extendConfig': (config, { isClient, isServer }) => {
if (config.server && config.server.hmr && config.server.hmr !== true) {
config.server.hmr.protocol = 'ws';
config.server.hmr.host = serverHost;
config.server.hmr.port = 3000;
config.server.host = 'tauri.localhost';
config.server.port = 3000;
}
},
}
})
Подробнее здесь: https://stackoverflow.com/questions/794 ... on-android
Ошибка соединения WebSocket при запуске Tauri Nuxt на Android ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1739980886
Anonymous
Я разрабатываю многоплатформенный проект (настольный компьютер, Android, iOS) с использованием Tauri 2 и Nuxt 3, но при запуске на Android я продолжаю встречаться с ошибкой, связанной с WebSocket, подобной этой.
Есть ли какие-либо идеи Это может мне помочь? - Строка 794 - MSG: [VITE] Не удалось подключиться к WebSocket (ошибка: webSocket закрыт без открытия.).
file: http: //tauri.localhost/_nuxt/@vite/client - строка 835 - MSG: [VITE] Ошибка: WebSocket закрыт без открытия.
File: http: //tauri.localhost/_nuxt/@vite/client - строка 835 - msg: [vite] Ошибка: websocket закрыт без открытия.
file: http: //tauri.localhost/_nuxt/@vite/client - Строка 443 - MSG: UNCAUNT (в Обещании) Ошибка: WebSocket закрыт без открытия.
Настройка проекта
tauri config: < /p>
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "nuxt-app",
"version": "0.1.0",
"identifier": "com.nuxt-app.dev",
"build": {
"frontendDist": "../dist",
"beforeDevCommand": "node preload-config.js && npm run dev -- --host",
"beforeBuildCommand": "npm run build",
"devUrl": "http://192.168.100.127:3000"
},
"app": {
"windows": [
{
"title": "nuxt-app",
"width": 1024,
"height": 600,
"resizable": true,
"fullscreen": false,
"devtools": true,
"additionalBrowserArgs": "--disable-web-security"
}
],
"security": {
"csp": "default-src 'self'; connect-src 'self' http://192.168.100.127:3000",
"capabilities": [
"remote-tag-capability"
]
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"android": {
"minSdkVersion": 26,
"versionCode": 1
}
}
}
< /code>
nuxt config < /p>
import UnoCSS from "unocss/vite";
import dns from 'node:dns';
import path from "path";
dns.setDefaultResultOrder("verbatim");
const host = process.env.TAURI_DEV_HOST || 'localhost'
const serverHost = process.env.VITE_HOST || 'localhost'
const port: number = process.env.PORT || 1420;
const devUrl = `http://${serverHost}:${port}`;
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
modules: [
'vuetify-nuxt-module',
'nuxt-echarts',
'nuxt-echarts',
'@unocss/nuxt',
'@nuxt/icon',
'@nuxtjs/google-fonts'
],
googleFonts: {
families: {
Roboto: true,
"Noto+Sans+JP": [400, 700]
},
display: "swap"
},
echarts: {
charts: ['BarChart', 'LineChart', 'PieChart'],
components: ['DatasetComponent', 'GridComponent', 'TooltipComponent'],
},
vuetify: {
moduleOptions: {
},
vuetifyOptions: {
}
},
// Enable SSG
ssr: false,
icon: {
customCollections: [
{
prefix: 'kinjiro-icons',
dir: './assets/kinjiro-icons'
},
],
},
ignore: ['**/src-tauri/**', '**/node_modules/**', '**/dist/**', '**/.git/**', '**/.nuxt/**', '**/.output/**'],
css: ['@/assets/css/global.css', 'vuetify/styles', '@mdi/font/css/materialdesignicons.css'],
devtools: { enabled: false },
sourcemap: {
server: true,
client: true
},
app: {
head: {
title: 'Nuxt Tauri App',
meta: [
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }
],
script: [
]
}
},
nitro: {
prerender: {
routes: [],
crawlLinks: false
},
preset: 'static',
devProxy: {
"/_nuxt/": {
target: devUrl, // Ensure the right port
changeOrigin: true,
prependPath: false,
ws: true
},
'/api': {
target: devUrl, // Thay bằng URL của backend
changeOrigin: true,
prependPath: false,
}
},
routeRules: {
'/_nuxt/**': { proxy: 'http://192.168.100.127:3000/**', cors: true }
},
experimental: {
nodeFetchCompat: true
}
},
routeRules: {
"/api/**": {
cors: true,
},
"/_nuxt/**": {
cors: true,
},
},
build: {
transpile: ["@tauri-apps/api", 'vuetify'], // Đảm bảo module của Tauri được bundle chính xác
},
devServer: {
host: "0.0.0.0", // Để chấp nhận kết nối từ mạng LAN
port: 3000
},
vite: {
plugins: [UnoCSS()],
esbuild: {
tsconfigRaw: {},
},
define: {
'process.DEBUG': true,
'import.meta.dev': false
},
ssr: {
external: ['@tauri-apps/api']
},
build: {
target: "esnext", // Hoặc thử "es2015" nếu vẫn lỗi
emptyOutDir: false
},
resolve: {
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue", ".css"],
alias: {
"@": path.resolve(__dirname, "./"),
"node_modules": path.resolve(__dirname, "./node_modules"),
},
},
clearScreen: false,
envPrefix: ['VITE_', 'TAURI_'],
server: {
ws: false,
strictPort: true,
cors: {
origin: '*',
methods: ['GET', 'POST'],
allowedHeaders: 'Content-Type Authorization'
},
hmr: {
protocol: 'ws',
host: 'tauri.localhost',
clientPort: port,
port: 3000
// server: { host: 'localhost', protocol: 'ws' }
},
watch: {
usePolling: true
},
// proxy: {
// '/api': {
// target: 'http://192.168.100.127:3000',
// changeOrigin: true,
// secure: false,
// }
// }
}
},
runtimeConfig: {
public: {
apiBase: devUrl
}
},
hooks: {
'vite:extendConfig': (config, { isClient, isServer }) => {
if (config.server && config.server.hmr && config.server.hmr !== true) {
config.server.hmr.protocol = 'ws';
config.server.hmr.host = serverHost;
config.server.hmr.port = 3000;
config.server.host = 'tauri.localhost';
config.server.port = 3000;
}
},
}
})
Подробнее здесь: [url]https://stackoverflow.com/questions/79444969/websocket-connection-error-when-running-tauri-nuxt-on-android[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия