vite-typescript template conflict with "allowImportingTsExtensions":true
Pre-flight checklist
- [X] I have read the contribution documentation for this project.
- [X] I agree to follow the code of conduct that this project uses.
- [X] 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"]
}
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 removed ts-node from my package,json. When I put ts-node back the error was resolved and the app started as expected.
The expectation here is that your resolver (e.g. your bundler, a runtime, or some other tool) is going to make these imports between .ts files work.
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.
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
I get that when I run npm run package 😀 (although unrelated??) it shares my sentiment
@jpmckown do you use ts-node in the start script, in vite config or somewhere?
@jpmckown do you use
ts-nodein the start script, in vite config or somewhere?
It's been a while but as I recall, ts-node is a dependency for Electron itself. So, the short answer is no, I think. Just leave the scripts as-is when generated by the forge.
Thanks, I added ts-node as dev dependency and it worked.
Edit: ts-node should be added as an optional peer dependency.
This is documented here: https://www.electronforge.io/config/typescript-configuration