1

Src folder structure:

|   index.tsx
|   
+---components
|       Nav.tsx
|       
\---pages
        login.tsx

index.tsx:

import { BrowserWindow, app } from "electron";
import React from "react";
import ReactDOM from "react-dom";
import Login from "./pages/login";

const main = async () => {
    ReactDOM.render(<Login />, document.getElementById("app"));
};
main();

login.tsx:

import React from "react";

interface loginProps {}

const Login: React.FC<loginProps> = ({}) => {
    return (
        <div>
            <h1>HelloWorld</h1>
        </div>
    );
};
export default Login;

webpack:

const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");

module.exports = {
    entry: "./src/index.tsx",
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: ["babel-loader", "ts-loader"],
                include: [path.resolve(__dirname, "src")],
            },
        ],
    },
    output: {
        publicPath: "public",
        filename: "bundle.js",
        path: path.resolve(__dirname, "public"),
    },
    resolve: {
        fallback: {
            path: require.resolve("path-browserify"),
        },
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: "./public/index.html",
        }),
    ],
    target: "electron-main",
};

babel:

{
    "presets": ["@babel/preset-env", "@babel/preset-react"]
}

I can't provide much more information on this since the compiler only outputs the error mentioned in title: ERROR in ./src/index.tsx Module not found: Error: Can't resolve './pages/login' in '..\src'. Something is probably not linked correctly. webpack 5.5.1 compiled with 1 error in 4971 ms

Vojin
  • 83
  • 7

2 Answers2

1

The problem was that I needed to add resolving extensions in the webpack config. Under resolve add:

extensions: [".ts", ".tsx", ".json", ".js"]

Also after that polyfill is needed refer to this post if you need help about it. Webpack cant resolve TypeScript modules

Vojin
  • 83
  • 7
0

Change the import of login, you have exported the login as default, but imported as normal export.

index.tsx:

import { BrowserWindow, app } from "electron";
import React from "react";
import ReactDOM from "react-dom";
import  Login  from "./pages/login"; // <== Changed this line

const main = async () => {
    ReactDOM.render(<Login />, document.getElementById("app"));
};
main();

Login.tsx

import React from "react";

interface loginProps {}


const Login: React.FC<loginProps> = ({}) => { //<== Changed this line
    return (
        <div>
            <h1>HelloWorld</h1>
        </div>
    );
};
export default Login;
Appy Mango
  • 1,298
  • 5
  • 16