can't import library from file into frontend react (using vite-electron)

13 Views Asked by At

In my vite-electron project, a file-based library js-globals installed via npm like so:

 "dependencies": {
        "@electron-toolkit/preload": "3.0.0",
        "@electron-toolkit/utils": "3.0.0",
        "@emotion/react": "11.11.4",
        "@emotion/styled": "11.11.0",
        "@mui/icons-material": "5.15.12",
        "@mui/material": "5.15.12",
        "@mui/styles": "5.15.12",
        "@nut-tree/nut-js": "3.1.2",
        "electron-updater": "6.1.8",
        "js-globals": "file:lib/js-globals-3.16.1.tgz"
    },

Cannot be imported into the React frontend in main.tsx with:

import React from "react"
import { createRoot } from "react-dom/client"
import { createTheme, ThemeProvider } from "@mui/material"
import { makeStyles } from "@mui/styles"

// import "js-globals"
// This broke production builds. Handle with care.
// The frontend does not seem to be able to find this library, and when main.tsx chokes the whole app displays as a blank screen.

Non-production builds that do not package this library into an executable work fine. It is only when this project is built for Production as an .exe that it seems main.tsx fails to find the library and dies. What do I need to configure to allow this library to be used by the React frontend in Production?

0

There are 0 best solutions below