forge icon indicating copy to clipboard operation
forge copied to clipboard

Can't move the forge config files in any subdirectory

Open LeonardoGentile opened this issue 1 year ago • 4 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.

Electron Forge version

7.2.0

Electron version

v28.1.4

Operating system

MacOs 13.6.3

Last known working Electron Forge version

No response

Expected behavior

Electron should start with no errors and modules should be loaded correctly

Actual behavior

SyntaxError: Cannot use import statement outside a module

Steps to reproduce

I've generated a new project with

npm init electron-app@latest my-new-app -- --template=vite-typescript

The forge.config.ts is located at the root of the project and if I launch the start script at this point everything works.

I want to move the config file into /tools/forge.config.ts, and I do so by also modifying the packages.json:

"config": {
    "forge": "./tools/forge.config.ts"
},

Now when I run the start script I get:

SyntaxError: Cannot use import statement outside a module

I've proceeded to also modify the tsconfig.json by adding the tools dir

"include": ["src", "tools"]

but nothing changed.

I've tried dozen of combination of these properties in tsconfig

 "target": "ESNext",
 "module": "commonjs",

I've also tried other combinations of the module property inside packages.json but still no luck.

It seems things only work if I put back forge.config.ts at the root of the project.

It this a misconfiguration on my side or some of the tools in the projects don't play well if I slightly modify the location of this file?

Additional information

No response

LeonardoGentile avatar Jan 19 '24 23:01 LeonardoGentile

Can you provide a minimal reproduction repo?

caoxiemeihao avatar Jan 22 '24 02:01 caoxiemeihao

Its not supported yet

ianho avatar Jan 23 '24 09:01 ianho

It seems things only work if I put back forge.config.ts at the root of the project.

That's correct, we only look for a forge.config file in the project root. The config.forge property from package.json is only used to specify the path to a Forge configuration file other than forge.config.js in your project root (since #2993, you can technically have your Forge config in e.g. a yaml file), not to set an arbitrary path within the project.

erikian avatar Jan 25 '24 02:01 erikian

The config.forge property from package.json is only used to specify the path to a Forge configuration file other than forge.config.js in your project root (since #2993, you can technically have your Forge config in e.g. a yaml file), not to set an arbitrary path within the project.

Thanks, it's understood but totally counterintuitive 🙂 So I can have another forge config file BUT at the condition that it should still be in the main root?

I guess this should be specified in the docs, it was quite tedious to understand why simply moving a file breaks the entire workflow 🤔

Thanks for the explanation 👍

LeonardoGentile avatar Jan 31 '24 18:01 LeonardoGentile