-
-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript ESM forge.config.ts error #3671
Comments
@codec-xyz I have found the same inconsistent behavior and to be honest I just tried every which combination until something was working for us (but feels very fragile and certainly not ideal long term). For us we went with using I believe it is related to: Screenshot of tsconfig tweaks that finally got it to work for us: |
@codec-xyz I am just glad I am not crazy and that you came to the same conclusion as me! I spent way too many hours (days) trying to figure this out and the imposter syndrome was starting to become real strong for me! haha |
I also encountered this problem. When I wanted to migrate to ESM according to the latest version of electron-store, I found that forge.config.ts did not support ESM. |
Using the template shared in the issue below worked for me initially, But later I needed to change the preload script output to cjs and moduleResolution to Node because some issues started showing up, Not sure if it was a problem on my end but with those changes everything seem to work fine. |
Having the same issue. |
This issue should be related to Electron forge v7.5.0 add support with ESM but, for this issue, nothing is changed. Repro
Maybe |
I found that With Yarn: yarn remove ts-node
yarn add --dev esbuild-register |
Thanks it works (youn need to install also I updated title of #3609 and added a comment (#3609 (comment)). |
I am running into the issue as well but with webpack. Anyone else have this issue? Steps to reproduceRun npm init electron-app@latest my-new-app -- --template=webpack-typescript Add "type": "module", to package.json ErrorFailed to load: electron-test/issue-3671/forge.config.js An unhandled rejection has occurred inside Forge:
|
rename forge.config.js to forge.config.cjs for supporting commonjs format |
A work-around I found is calling the Forge cli command script's with something like "scripts": {
"start": "tsx node_modules/@electron-forge/cli/src/electron-forge-start",
"package": "tsx node_modules/@electron-forge/cli/src/electron-forge-package",
"make": "tsx node_modules/@electron-forge/cli/src/electron-forge-make",
"publish": "tsx node_modules/@electron-forge/cli/src/electron-forge-publish"
} |
Pre-flight checklist
Electron Forge version
7.4.0
Electron version
v31.3.1
Operating system
Windows 11
Last known working Electron Forge version
No response
Expected behavior
To not get an error when using a Typescript ESM forge.config.ts.
Actual behavior
Error are listed under the steps to reproduce section.
Steps to reproduce
Run
npm init electron-app@7.4.0 my-new-app -- --template=vite-typescript
Add
"type": "module",
topackage.json
Note
To make other parts of the template work with "type": "module"
In
vite.main.config
changeformats: ['cjs'],
toformats: ['es'],
In
vite.preload.config
changeformat: 'cjs',
toformat: 'es',
In
src/main.ts
changeand replace
__dirname
withimport.meta.dirname
You can also
npm install --save-dev @types/electron-squirrel-startup
and intsconfig.json
change"module": "commonjs",
→"module": "ESNext",
to make typescript happy.Run
npm run start
This result in this error...
However changing
forge.config.ts
toforge.config.js
(and removing the type definitions) makes the error go away. So seemingly JS ES modules work but TS ES modules do not work.Another option is changing the
forge.config.ts
to aforge.config.cts
but it does not work with"module": "ESNext"
(or other ES module options) in thetsconfig.json
which gives the error...Additional information
No response
The text was updated successfully, but these errors were encountered: