Webpack 5 bundle.js doesn't include all the src content - reactjs

After I removed "dist" folder and re-build the project using webpack it starts producing 0 bytes bundle.js
Here is webpack.config.js:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
entry: './src/index.tsx',
devtool: 'source-map',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{ test: /\.svg$|/i, use: 'raw-loader' },
{ test: /\.tsx?$/i, use: [{ loader: 'ts-loader', options: { transpileOnly: true } }], exclude: /node_modules/, },
{ test: /\.css$/i, use: ['style-loader', 'css-loader'] },
{ test: /\.s[ac]ss$/i, use: ["style-loader", "css-loader", "sass-loader"] },
],
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
hot: true,
port: 9000,
},
plugins: [new HtmlWebpackPlugin()],
};
Here is 'index.tsx':
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import "antd/dist/antd.css";
const root = document.createElement('div');
root.setAttribute('id', 'root');
document.body.appendChild(root);
const MyApp = () => (
<React.Fragment>
<App />
</React.Fragment>
);
ReactDOM.render(<MyApp />, document.getElementById('root'));
Here is package.json scripts:
"scripts": {
"start": "node node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress",
"build": "node node_modules/webpack/bin/webpack.js -p --progress --color"
},
Here are dependencies:
"devDependencies": {
"#types/react-virtualized": "^9.21.11",
"#types/react-window": "^1.8.3",
"#webpack-cli/serve": "^1.5.1",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.2",
"less": "^4.1.1",
"less-loader": "^10.0.1",
"mobx-react-devtools": "^6.1.1",
"raw-loader": "^4.0.2",
"sass": "^1.35.1",
"sass-loader": "^12.1.0",
"ts-loader": "^9.2.3",
"webpack": "^5.43.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.2"
}
As a result when I run 'npm run build' I'm getting:
PS D:\coding\video-demo> npm run build
> video-demo#0.1.0 build D:\coding\video-demo
> node node_modules/webpack/bin/webpack.js -p --progress --color
asset index.html 243 bytes [emitted]
asset bundle.js 0 bytes [emitted] [minimized] (name: main)
./src/index.tsx 504 bytes [built] [code generated]
webpack 5.44.0 compiled successfully in 669 ms
bundle.js is 0 bytes.
What might happen that now cause issues with building bundle.js?
EDIT: after changing webpack-cli version to 4.7.2 (latest) and modifying build script to just "webpack" I was able to get bundle.js with some code inside. However, there is the only index.tsx content inside bundle.js. It seems that wepback can't build the graph of imports. Does anyone aware of why it might happen? Maybe something wrong in tsconfig.json.
tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"module": "esnext",
"target": "es5",
"jsx": "react-jsx",
"sourceMap": true,
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": false,
"moduleResolution": "node",
"resolveJsonModule": true
},
"include": [
"src"
],
}

Finally, after hours of applying different configurations, I was able to make it work with webpack 5. Not sure what exactly was the issue, seems it was some kind of combination of different things, from different configs.
I replaced ts-loader with babel and changed tsconfig.json to:
{
"compilerOptions": {
"experimentalDecorators": true,
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
}

Related

Webpack Cannot read properties of null (reading 'useEffect')

I am trying to make one React Component Package but i am getting this error after i create bundle file with webpack. I am trying to make one Component with Typescript. I didn't create project from CRA. React and React-Dom package is lastest version. when i delete the ts-loader line from webpack it is working well but decleration packages are not generating.
react.development.js:1634 Uncaught TypeError: Cannot read properties of null (reading 'useEffect')
at Object.useEffect (react.development.js:1634:1)
at l (index.js:1:1)
at renderWithHooks (react-dom.development.js:16305:1)
at mountIndeterminateComponent (react-dom.development.js:20074:1)
at beginWork (react-dom.development.js:21587:1)
at beginWork$1 (react-dom.development.js:27426:1)
at performUnitOfWork (react-dom.development.js:26557:1)
at workLoopSync (react-dom.development.js:26466:1)
at renderRootSync (react-dom.development.js:26434:1)
at recoverFromConcurrentError (react-dom.development.js:25850:1)
My Webpack File
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: path.resolve(__dirname, "./src/index.tsx"),
resolve: {
extensions: [".tsx", ".ts", ".js"],
extensionAlias: {
".js": [".js", ".ts"],
".cjs": [".cjs", ".cts"],
".mjs": [".mjs", ".mts"]
},
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
},
],
},
{ test: /\.([cm]?ts|tsx)$/, loader: "ts-loader" },
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
type: "asset/resource",
},
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: "asset/inline",
},
],
},
externals: [nodeExternals()],
output: {
path: path.resolve(__dirname, "./dist"),
filename: "index.js",
libraryTarget: "commonjs",
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "./src/index.html"),
}),
],
stats: "errors-only",
};
Package.json file content
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack serve --config webpack.config.js --open",
"build": "rm -rf ./dist && webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"#babel/core": "^7.20.12",
"#babel/plugin-transform-runtime": "^7.19.6",
"#babel/preset-env": "^7.20.2",
"#babel/preset-react": "^7.18.6",
"#babel/preset-typescript": "^7.18.6",
"#types/react": "^18.0.26",
"#types/react-dom": "^18.0.10",
"babel-loader": "^9.1.2",
"html-webpack-plugin": "^5.5.0",
"ts-loader": "^9.4.2",
"typescript": "^4.9.4",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1",
"webpack-node-externals": "^3.0.0"
}
}
TS Config content is;
{
"compilerOptions": {
"target": "ES5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ /* Type declaration files to be included in compilation. */,
"declaration": true,
"outDir": "dist",
"lib": [
"DOM",
"ESNext"
] /* Specify library files to be included in the compilation. */,
"jsx": "react-jsx" /* Specify JSX code generation: 'preserve', 'react-native', 'react' or 'react-jsx'. */,
"noEmit": false /* Do not emit outputs. */,
"isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"resolveJsonModule": true,
"sourceMap": true,
// "allowJs": true /* Allow javascript files to be compiled. Useful when migrating JS to TS */,
// "checkJs": true /* Report errors in .js files. Works in tandem with allowJs. */,
},
"include": ["src/**/*"]
}

React v18 + MUI v5 + Weback 5 : Not working when create as npm package

I am trying to create simple react package that can be used in react apps.
I am using these main libraries: React(18.2.0), Webpack(5.4.0), mui/material(5.11.2), typescript(4.9.4).
I am adding this package in my react app using local dependency("packagename": "file:../package").
It is working fine without mui. But when i add mui it's building fine in package but gives error in react app where package is used.
Below is webpack configurations of package.
const path = require("path");
const webpack = require("webpack");
module.exports = (env) => ({
mode: env.NODE_ENV,
watch: env.NODE_ENV === "development",
entry: {
app: path.join(__dirname, "src", "index.tsx"),
},
output: {
libraryTarget: "umd",
library: "libname",
filename: "index.js",
path: path.resolve(__dirname, "dist"),
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: "/node_modules/",
options: {
configFile: path.resolve(__dirname, "tsconfig.json"),
},
},
{
test: /\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
importLoaders: 1,
modules: {
auto: true,
localIdentName:
env.NODE_ENV === "development"
? "[local]__[hash:base64:5]"
: "[hash:base64:5]",
},
},
},
],
include: /\.module\.css$/,
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
exclude: /\.module\.css$/,
},
{
test: /\.svg$/,
use: [
{
loader: "#svgr/webpack",
options: {
svgoConfig: {
plugins: [{ removeViewBox: false }],
},
},
},
{
loader: "svg-url-loader",
},
],
},
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: "url-loader",
},
],
},
{
test: /\.(woff|woff2)$/,
use: {
loader: "url-loader",
},
},
],
},
plugins: [
new webpack.DefinePlugin({
"process.env.STAGE": JSON.stringify(env.STAGE),
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
],
externals: {
react: {
commonjs: "react",
commonjs2: "react",
amd: "react",
root: "React",
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "react-dom",
root: "ReactDOM",
},
},
});
This is package.config.
"dependencies": {
"#emotion/react": "^11.10.5",
"#emotion/styled": "^11.10.5",
"#mui/material": "^5.11.2"
},
"devDependencies": {
"#svgr/webpack": "^5.4.0",
"#types/node": "^12.12.42",
"#types/react": "^18.0.26",
"#types/react-dom": "^18.0.10",
"css-loader": "^4.3.0",
"style-loader": "^1.3.0",
"svg-url-loader": "^6.0.0",
"ts-loader": "^8.0.7",
"typescript": "^4.9.4",
"url-loader": "^4.1.1",
"webpack": "^5.4.0",
"webpack-cli": "^4.2.0",
"webpack-node-externals": "^3.0.0"
},
"files": [
"dist/index.js",
"dist/index.d.ts",
"dist/*.png",
"dist/*.jpg"
],
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Below is tsconfig.json
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"downlevelIteration": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": false,
"jsx": "react",
"allowJs": true,
"declaration": true,
"outDir": "./dist"
},
I am getting below error in react app in which package is used. That reach app is created using create-react-app and using latest react v18.
I tried researching and tried by changing several options in webpack config as well. But i am not able to figure this out.
Any help is appriciated.
React 18 introduces a new root API, Change your index.js:
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
For Typescript:
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);

Webpack 5 & Jest - Property 'toBeInTheDocument' does not exist on type 'JestMatchers<HTMLElement>'

I can't get the typings for Jest to work with Webpack 5 and TypeScript, I've tried other solutions for the same problem. The problem is only with "screen" and "toBeInTheDocument" in my example test below. I'm leaning toward it being an ESLint configuration issue.
I can't run the tests, they fail with Property 'toBeInTheDocument' does not exist on type 'JestMatchers<HTMLElement>'.. I'm using Yarn 3.1.0. I've tried this answer and many others, including importing the types through tsconfig.json. What am I doing wrong?
Example test (src/components/Example/spec/test.spec.tsx):
import * as React from 'react';
import { render, screen } from '#testing-library/react';
import { Example } from './Example';
import "#testing-library/jest-dom/extend-expect";
import "#testing-library/jest-dom";
test("Renders correctly", () => {
render(<Example />);
const example = screen.getByAltText("Example");
expect(example).toBeInTheDocument();
});
jest.config.js:
module.exports = {
// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: ['node_modules', '<rootDir>/src'],
// A map to module names that allow stubbing out resources with a single module
moduleNameMapper: {
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
},
// Preset for our Jest configuration base
preset: 'ts-jest/presets/js-with-ts',
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
// Environment used for testing
testEnvironment: 'jsdom',
};
webpack.config.js:
/* eslint-disable */
const { ModuleFederationPlugin } = require('webpack').container;
const path = require('path');
const packageJsonName = require('./package.json').name;
const packageJsonDeps = require('./package.json').dependencies;
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
mode: 'development',
entry: path.resolve(__dirname, 'src', 'index.ts'),
devServer: {
client: {
overlay: true,
},
static: {
directory: './dist',
},
port: 3001,
historyApiFallback: true
},
module: {
rules: [
{
test: /\.(tsx|ts|jsx)?$/,
//exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
experimentalWatchApi: true,
transpileOnly: true,
},
},
],
},
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader'],
},
],
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: 'auto',
},
resolve: {
cacheWithContext: false,
extensions: ['.js', '.ts', '.tsx', '.jsx'],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, './tsconfig.json'),
}),
],
symlinks: false,
},
};
package.json:
{
"scripts": {
"start": "webpack-cli serve",
"build": "webpack --mode production",
"dev": "webpack serve --progress",
"test": "jest",
"test:coverage": "jest --coverage --watchAll=false",
"test:watch": "jest --watch"
},
"dependencies": {
"react": "17.0.2",
"react-router-dom": "^5.2.0",
},
"devDependencies": {
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "12.1.2",
"#testing-library/user-event": "13.5.0",
"#types/jest": "27.0.2",
"#types/react": "^17.0.33",
"#types/react-router-dom": "5.3.2",
"#typescript-eslint/eslint-plugin": "5.2.0",
"#typescript-eslint/parser": "4.33.0",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-jest": "25.2.2",
"eslint-plugin-react": "7.26.1",
"eslint-plugin-react-hooks": "4.2.0",
"jest": "^27.3.1",
"prettier": "2.4.1",
"ts-jest": "^27.0.7",
"ts-loader": "^9.2.6",
"tslib": "^2.3.1",
"typescript": "~4.3.5",
"webpack": "5",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.3.1"
}
}
And tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"declaration": true,
"esModuleInterop": true,
"importHelpers": true,
"jsx": "react",
"lib": ["es6", "dom"],
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"outDir": "dist",
"resolveJsonModule": true,
"rootDir": ".",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es6"
},
"include": ["**/*.ts", "**/*.tsx", "**/*.jsx", "**/*.js"],
"exclude": [
"dist",
"node_modules"
]
}
And setupTests.ts is just: import '#testing-library/jest-dom/extend-expect';
Thanks for any pointers.
Install the types using:
npm i #types/testing-library__jest-dom -D
Please make sure that the correct types are installed in your project. i.e.
npm i -D #testing-library/jest-dom#^4.2.4
From my experience the Typescript types seem to be missing from version 5.x

Module not found, webpack alias with typescript react

I'm trying to implement some alias in webpack. What I want to do, is that instead of using this to import a component on App.js from the folder components.
./components/layout/Header/Header
I want this:
#components/layout/Header/Header
That is, in order to avoid problems when future nested folders will be created. What I've done is coding this on the webpack.config.js
module.exports = {
context: __dirname,
entry: './src/index.js',
output: {
path: path.resolve( __dirname, 'dist' ),
filename: 'main.js',
},
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx'],
alias: {
src: path.resolve(__dirname, 'src'),
assets: path.resolve(__dirname, 'src/assets'),
components: path.resolve(__dirname, 'src/components'),
}
}
.
.
.
};
And this on the tsconfig.json file:
{
"compilerOptions": {
"jsx": "react-jsx",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"baseUrl": ".",
"paths": {
"#": ["./src/*"],
"#assets": ["./src/assets/*"],
"#components": ["./src/components/*"]
},
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
},
"include": [
"src"
]
}
When I run "npm run start" that is a "react-scripts start", I get the following error:
./src/App.js
Module not found: Can't resolve '#components/layout/Header/Header' in 'C:\Users\Angel\Documents\React\thermometer\src'
Also, I've noticed that when I run "npm run start", the object "paths" that I've created on the tsconfig.json file, is deleted and the file resets. I am new creating react projects from zero. Thanks in advance!
Looking at the documentation of Webpack, it doesn't mention automatically prepending the alias with #. Since it isn't specified there, Webpack (and therefore react-scripts start) doesn't know what #components points to.
I actually don't know whether Webpack supports aliases starting with # (e.g. a suffix of $ has specific meaning for Webpack, and # is usually for scoped packages), but if it does, you'll have to alter your resolve.alias to include the #.

Can't import React component from another file

I'm new to react and I'm having issues with importing a component from another file.
import React from 'react';
import ReactDOM from 'react-dom';
import '../resources/styles.scss';
import WelcomeView from '../views/welcome/WelcomeView';
const Root: React.FC = () => {
return (
<div>
<WelcomeView />
</div>
);
};
ReactDOM.render(<Root />, document.getElementById('root'));
With the above code, I get this error: Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
I've been googling this for hours and everyone has been saying that it's an import issue, but I think I'm using my exports correctly.
Here is the WelcomeView component which I'm trying to import from another file:
import styles from './WelcomeView.scss';
import React from 'react';
const WelcomeView: React.FC = () => {
return (
<div className={styles.welcome}>
Welcome
</div>
);
};
export default WelcomeView;
If I inline WelcomeView in the same file as my Root component, then it works. But doesn't work when it's in a separate file. I think it might have something to do with my tsconfig?
{
"compilerOptions": {
"esModuleInterop": true,
"isolatedModules":true,
"jsx": "react",
"lib": ["esnext", "dom"],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,
"noEmit": true,
"target": "es5",
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"skipLibCheck": true,
"strict": true,
"incremental": true,
"noFallthroughCasesInSwitch": true
},
"include": ["frontend/src/root/app.tsx"],
}
My package.json dependencies:
"devDependencies": {
"#teamsupercell/typings-for-css-modules-loader": "^2.4.0",
"#types/react": "^17.0.0",
"#types/react-dom": "^17.0.0",
"#babel/cli": "^7.1.0",
"#babel/core": "^7.1.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.2.1",
"awesome-typescript-loader": "^5.2.1",
"css-loader": "^1.0.1",
"node-sass": "^5.0.0",
"sass-loader": "^10.1.0",
"style-loader": "^2.0.0",
"typescript": "^4.1.2",
"webpack": "^4.40.2",
"webpack-cli": "^3.1.1"
},
"dependencies": {
"react": "^16.5.2",
"react-dom": "^16.5.2"
}
Webpack:
const path = require('path');
module.exports = {
entry: './frontend/src/root/root.tsx',
mode: 'development',
module: {
rules: [
{
test: /\.scss$/,
loaders: [
'style-loader',
'#teamsupercell/typings-for-css-modules-loader',
'css-loader?modules',
'sass-loader',
],
},
{
test: /\.(ts|tsx)$/,
loader: 'awesome-typescript-loader',
},
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: { presets: ['#babel/env'] },
},
],
},
resolve: { extensions: ['*', '.css', '.scss', '.ts', '.tsx', '.js', '.jsx'] },
output: {
path: path.resolve(__dirname, 'frontend/public/'),
filename: 'bundle.js',
},
};
It may be caused by re-importing the relevant component or by different case among the connected components.
Try to include your entire src folder in tsconfig include.
Okay this is kind of underwhelming, but it turns out the files were corrupt since I'm using OSX. I figured it out from this question:
webpack --watch isn't compiling changed files
I just deleted all the files and then recreated them and it worked.

Resources