Repository navigation
Description
Pre-flight checklist
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project uses.
- I have searched the issue tracker for a bug that matches the one I want to file, without success.
Electron Forge version
7.2.0
Electron version
v29.0.0
Operating system
Win10 x64 Pro 22H2 19045.3208
Last known working Electron Forge version
7.2.0
Expected behavior
✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies
✔ Running generateAssets hook
......
Actual behavior
✔ Checking your system
✔ Locating application
✖ Loading configuration
› Unable to use specified module loaders for ".ts".
◼ Preparing native dependencies
◼ Running generateAssets hook
An unhandled rejection has occurred inside Forge:
Error: Unable to use specified module loaders for ".ts".
at Object.exports.prepare (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules\rechoir\index.js:58:11)
at exports.default (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules@electron-forge\core\src\util\forge-config.ts:117:17)
at async Task.task (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules@electron-forge\core\src\api\start.ts:63:29)
at async Task.run (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules\listr2\dist\index.cjs:978:11)
at async C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules\p-map\index.js:57:22
Steps to reproduce
- Execute command
npm init electron-app@latest DLR_SA -- --template=vite-typescript. - Add this item to tsconfig.json:
{
"compilerOptions": {
//...
"allowImportingTsExtensions": true,
"noEmit": true,
//whether add "noEmit" at here won't make any different.
//...
}
- Run forge start script.
npm run startorelectron-forge start, givensame error message exclude the path.
Additional information
Full tsconfig.json file (which one make error):
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"noImplicitAny": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": "dist",
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"allowImportingTsExtensions": true,
},
"include": ["src"]
}
Activity
jpmckown commentedon Mar 2, 2024
Want to share my experience with this error here;
I was running into the same error
Error: Unable to use specified module loaders for ".ts".but I was not using the configuration above. What ended up being the cause was that I had removedts-nodefrom my package,json. When I putts-nodeback the error was resolved and the app started as expected.aentwist commentedon May 6, 2024
https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions
I need tsx for React. React wants a module/bundler setup while forge only works with commonjs/node? So maybe commonjs/node isn't cutting it here? If we can use module/bundler then it will "make these imports between .ts files work".
A potential workaround might be to nest the React package.json/tsconfig instead of flattening it onto electron so that both can have their own? Not really a fan of this though, nor have I gotten it to work yet.
aentwist commentedon May 6, 2024
I get that when I run
npm run package😀 (although unrelated??) it shares my sentimentrtritto commentedon May 29, 2024
@jpmckown do you use
ts-nodein the start script, in vite config or somewhere?jpmckown commentedon May 29, 2024
It's been a while but as I recall,
ts-nodeis a dependency for Electron itself. So, the short answer is no, I think. Just leave the scripts as-is when generated by the forge.rtritto commentedon May 29, 2024
Thanks, I added
ts-nodeas dev dependency and it worked.Edit:
ts-node should be added as an optional peer dependency.
erickzhao commentedon Jan 31, 2025
This is documented here: https://www.electronforge.io/config/typescript-configuration