forge icon indicating copy to clipboard operation
forge copied to clipboard

TypeScript Forge configuration fails to load for Node >=23.6

Open SebastianRzk opened this issue 1 year ago • 7 comments

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.

Forge version

7.6.1 aswell as 7.7.0

Electron version

34.0.0

Operating system

Arch Linux

Last known working Forge version

7.7.0 but with Node 23.5

Expected behavior

The command npm run package should work on node-versions greater than 23.5 as "good" as on version 23.5 and less.

Actual behavior

On node 23.6, 23.7 and 23.8:

pm run package

> [email protected] package
> electron-forge package

✔ Checking your system
✖ Preparing to package application
  ›
    1. Cannot find module '/tmp/test/my-app/webpack.main.config' imported from /tmp/test/my-app/forge.config.ts
    2. Cannot find module '/tmp/test/my-app/webpack.main.config' imported from /tmp/test/my-app/forge.config.ts
◼ Running packaging hooks
◼ Packaging application
◼ Running postPackage hook

(node:7471) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Failed to load: /tmp/test/my-app/forge.config.ts
(node:7471) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///tmp/test/my-app/forge.config.ts is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /tmp/test/my-app/package.json.

An unhandled rejection has occurred inside Forge:
Error [ERR_MODULE_NOT_FOUND]: 
1. Cannot find module '/tmp/test/my-app/webpack.main.config' imported from /tmp/test/my-app/forge.config.ts
2. Cannot find module '/tmp/test/my-app/webpack.main.config' imported from /tmp/test/my-app/forge.config.ts
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:719:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:643:25)
    at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:678:38)
    at ModuleLoader.resolveSync (node:internal/modules/esm/loader:701:52)
    at #cachedResolveSync (node:internal/modules/esm/loader:662:25)
    at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:390:50)
    at new ModuleJobSync (node:internal/modules/esm/module_job:342:34)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:363:11)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1565:24)
    at Module._compile (node:internal/modules/cjs/loader:1716:5)
    at Object.loadTS [as .ts] (node:internal/modules/cjs/loader:1826:10)
    at Module.load (node:internal/modules/cjs/loader:1469:32)
    at Function._load (node:internal/modules/cjs/loader:1286:12)

Steps to reproduce

  1. Generate empty project from template: npx create-electron-app@latest my-app --template=webpack-typescript
  2. Change into the directory cd my-app
  3. Run npm run package

Additional information

When I switch with nvm to node 23.5, it works again

SebastianRzk avatar Mar 08 '25 12:03 SebastianRzk

Hey @SebastianRzk, thanks for raising this issue. It seems like the way we import features is incompatible with the default behaviour of the --experimental-strip-types feature, which was unflagged in v23.6.0 of Node.js (https://nodejs.org/en/blog/release/v23.6.0).

I verified this by turning the feature off after running your repro steps:

NODE_OPTIONS="--no-experimental-strip-types" npm run package

erickzhao avatar Mar 10 '25 19:03 erickzhao

hello @erickzhao, for the moment is there any other workaround besides running NODE_OPTIONS="--no-experimental-strip-types" npm run start

mohamedrhoulam avatar Mar 19 '25 00:03 mohamedrhoulam

@mohamedrhoulam downgrading your Node.js version would work as well :)

erickzhao avatar Mar 19 '25 00:03 erickzhao

Just to add, for Windows users, the same bug occurs and the work-around is nearly the same

$ENV:NODE_OPTIONS="--no-experimental-strip-types"
npm run start

pedro-w avatar Mar 26 '25 12:03 pedro-w

This still does not work on v7.8.0 (Mar 25), I believe the fix should be available in the next version bump which has not been released yet, May I know if it will be released soon?

KKghub avatar May 02 '25 16:05 KKghub

Oops, I went on vacation like a week after getting that PR landed. I'm back now, though, so we'll look to get a new release out soon!

erickzhao avatar May 02 '25 17:05 erickzhao

Do you have any plan to release the new version? The flowers I've been waiting for have all withered

Crazh3 avatar May 09 '25 07:05 Crazh3