Skip to content

Using ESM in Webpack-TypeScript Template #3780

Open
@fras2560

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.6.0

Electron version

33.2.1

Operating system

macOS Sequoia 15.1

Last known working Electron Forge version

No response

Expected behavior

Able to start the template

Actual behavior

npm run start

[email protected] start
electron-forge start

✔ Checking your system
✔ Locating application
✖ Loading configuration

1. Must use import to load ES Module: /fresh/forge.config.ts
require() of ES modules is not supported.
require() of /resh/forge.config.ts from
/fresh/node_modules/@electron-forge/core/helper/dynamic-import.js is an ES module file as
it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES
modules.
Instead change the requiring code to use import(), or remove "type": "module" from
/Users/dallas/Documents/Github/electron-test/fresh/package.json.
2. Unknown file extension ".ts" for /fresh/forge.config.ts
◼ Preparing native dependencies
◼ Running generateAssets hook
◼ Running preStart hook

Failed to load: fresh/forge.config.ts

An unhandled rejection has occurred inside Forge:
Error:

  1. Must use import to load ES Module: /fresh/forge.config.ts
    require() of ES modules is not supported.
    require() of /fresh/forge.config.ts from /fresh/node_modules/@electron-forge/core/helper/dynamic-import.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
    Instead change the requiring code to use import(), or remove "type": "module" from /fresh/package.json.

  2. Unknown file extension ".ts" for /fresh/forge.config.ts

Steps to reproduce

Run npm init [email protected] my-new-app -- --template=vite-typescript

Add "type": "module", to package.json

Now run npm start

Additional information

I am investigating a project and the work required to update to ESM. Since electron-store is a native ESM now and using an older version of the store. I was running into some issue with the project when following

https://www.electronjs.org/docs/latest/tutorial/esm
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

I tried implementing the various suggestions seen in

#3671
#3684

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions