gpt4 book ai didi

javascript - Webpack无法在Electron应用程序中从Nodejs打包https

转载 作者:行者123 更新时间:2023-12-03 12:37:16 24 4
gpt4 key购买 nike

我的webpack配置似乎可以成功构建,但是尽管在配置中定义了导入,但我仍获得了未定义的对https包的引用。
我不确定我的webpack是否配置错误,或者在定义axios实例时是否以某种方式调用https错误。任何指针将不胜感激。webpack.config.js

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");
const BUILD_DIR = path.resolve(__dirname, "./build/app");
const SRC_DIR = path.resolve(__dirname, "./src/app");

module.exports = {
entry: {
main: SRC_DIR + "/index.tsx",
},
output: {
filename: "bundle.js",
path: BUILD_DIR,
},
resolve: {extensions: [".ts", ".tsx", ".js", ".jsx"]},
module: {
rules: [
{test: /\.tsx?$/, include: SRC_DIR, use: "awesome-typescript-loader"},
{test: /\.(j|t)sx?$/, enforce: "pre", use: "source-map-loader"},
{test: /\.css$/, use: ["style-loader", "css-loader"]},
{test: /\.(jpg|png|gif|jpeg|woff|woff2|eot|ttf|svg)$/, use: "url-loader?limit=100000"},
{test: /\.html$/, use: "html-loader"},
],
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/app/html/index.html",
filename: "./index.html",
}),
new webpack.ExternalsPlugin("commonjs", ["electron", "https"]),
],
target: "electron-renderer",
};
Client Instance
import Axios from "axios";
import https from "https";

export const clientInstance = Axios.create({
baseURL: "https://127.0.0.1:2999/liveclientdata/allgamedata",
httpsAgent: new https.Agent({ // <---- this is where it fails. the reference to https.
rejectUnauthorized: false,
}),
});
error
Uncaught ReferenceError: require is not defined
at Object.https (bundle.js:7743)
at __webpack_require__ (bundle.js:7766)
at eval (webpack://express-electron-core/./src/app/components/plugins/axios.ts?:9)
at Object../src/app/components/plugins/axios.ts (bundle.js:316)
at __webpack_require__ (bundle.js:7766)
at eval (webpack://express-electron-core/./src/app/components/hooks/useAssociatedAccounts.ts?:5)
at Object../src/app/components/hooks/useAssociatedAccounts.ts (bundle.js:173)
at __webpack_require__ (bundle.js:7766)
at eval (webpack://express-electron-core/./src/app/components/hooks/index.ts?:4)
at Object../src/app/components/hooks/index.ts (bundle.js:140)

最佳答案

main.ts

const mainWindow = new BrowserWindow({
webPreferences:{
contextIsolation: true //this was the issue
}
});

关于javascript - Webpack无法在Electron应用程序中从Nodejs打包https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66201397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com