address root cause

This commit is contained in:
jackkav
2026-06-08 14:39:58 +02:00
committed by Jack Kavanagh
parent c33ea973c4
commit f0e5bf4378
7 changed files with 6 additions and 17 deletions

View File

@@ -19,7 +19,7 @@ export async function sendRequest(
try {
const requestOptions = requestToCurlOptions(request, settings);
const nodejsCurlRequest =
process.type === 'renderer'
typeof window !== 'undefined' && window.bridge != null
? window.bridge.curlRequest
: (await import('insomnia/src/main/network/libcurl-promise')).curlRequest;

View File

@@ -1,7 +1,3 @@
// NOTE: this file should not be imported by electron renderer because node-libcurl is not-context-aware
// Related issue https://github.com/JCMais/node-libcurl/issues/155
import { invariant } from '../../utils/invariant';
invariant(process.type !== 'renderer', 'Native abstractions for Nodejs module unavailable in renderer');
import fs from 'node:fs';
import path from 'node:path';
import type { Readable, Writable } from 'node:stream';

View File

@@ -1,7 +1,3 @@
if (process.type === 'renderer') {
throw new Error('multipart.ts unavailable in renderer');
}
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

View File

@@ -4,7 +4,7 @@ import { invariant } from 'insomnia/src/utils/invariant';
import { platform } from 'insomnia-data/common';
// TODO: consider how this would work in a webworker context
const isRenderer = process.type === 'renderer';
const isRenderer = typeof window !== 'undefined';
export const init = (renderPurpose: RenderPurpose = 'general'): { app: AppContext } => ({
app: {

View File

@@ -58,7 +58,7 @@ export function init(): {
const settingFollowRedirects = settings?.followRedirects ? 'on' : 'off';
const { request: originRequest, caCertficatePath = null } = options;
const curlRequest =
process.type === 'renderer' || process.type === 'worker'
typeof window !== 'undefined' && window.main != null
? window.main.curlRequest
: // when exeucted in Inso;
(await import('../../main/network/libcurl-promise')).curlRequest;

View File

@@ -129,7 +129,8 @@ export async function getPlugins(force = false): Promise<Plugin[]> {
// Make sure the default directories exist
const pluginPath = path.resolve(
process.env['INSOMNIA_DATA_PATH'] || (process.type === 'renderer' ? window : electron).app.getPath('userData'),
process.env['INSOMNIA_DATA_PATH'] ||
(typeof window !== 'undefined' && window.app != null ? window : electron).app.getPath('userData'),
'plugins',
);
@@ -299,7 +300,7 @@ export function getPluginCommonContext({
...pluginNetwork.init(),
util: {
openInBrowser: async (url: string) =>
process.type === 'renderer' || process.type === 'worker'
typeof window !== 'undefined' && window.main != null
? window.main.openInBrowser(url)
: electron.shell.openExternal(url),
models: {

View File

@@ -15,10 +15,6 @@ export default defineConfig(({ mode }) => {
'__IS_RENDERER__': JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify(mode),
'process.env.INSOMNIA_ENV': JSON.stringify(mode),
// Only apply in production builds: Rollup does text substitution (safe).
// In dev mode Vite uses runtime assignment via env.mjs, which throws
// TypeError because process.type is read-only in Electron's renderer process.
...(!__DEV__ ? { 'process.type': JSON.stringify('renderer') } : {}),
},
server: {
port: pkg.dev['dev-server-port'],