Skip to content
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

Built-in templates do not start #3019

Closed
3 tasks done
cwellsx opened this issue Oct 29, 2022 · 17 comments
Closed
3 tasks done

Built-in templates do not start #3019

cwellsx opened this issue Oct 29, 2022 · 17 comments

Comments

@cwellsx
Copy link

cwellsx commented Oct 29, 2022

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

6.0.0-beta.70

Electron version

v21.2.0

Operating system

Windows 10 Version 21H1 Build 19043.2130

Last known working Electron Forge version

6.0.0-beta.65

Expected behavior

After running the following commands

yarn create electron-app test --template=webpack
cd test
npm run start

then the empty application should start.

Actual behavior

test>npm run start

test@1.0.0 start
electron-forge start

√ Checking your system
√ Locating Application

An unhandled rejection has occurred inside Forge:
Error: package.json for app does not have any devDependencies

Electron Forge was terminated. Location:
{}

Steps to reproduce

See above

Additional information

Running node_modules\.bin\electron-forge --version returns this:

√ Checking your system
 6.0.0-beta.70

However according to packages.json it's beta.69 that's installed.

{
  "name": "test",
  "productName": "test",
  "version": "1.0.0",
  "description": "My Electron application description",
  "main": ".webpack/main",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "lint": "echo \"No linting configured\""
  },
  "keywords": [],
  "author": {
    "name": "cwellsx",
    "email": "cwellsx@example.com"
  },
  "license": "MIT",
  "devDependencies": {
    "@electron-forge/cli": "^6.0.0-beta.69",
    "@electron-forge/maker-deb": "^6.0.0-beta.69",
    "@electron-forge/maker-rpm": "^6.0.0-beta.69",
    "@electron-forge/maker-squirrel": "^6.0.0-beta.69",
    "@electron-forge/maker-zip": "^6.0.0-beta.69",
    "@electron-forge/plugin-webpack": "6.0.0-beta.69",
    "@vercel/webpack-asset-relocator-loader": "1.7.3",
    "css-loader": "^6.0.0",
    "electron": "21.2.0",
    "node-loader": "^2.0.0",
    "style-loader": "^3.0.0"
  },
  "dependencies": {
    "electron-squirrel-startup": "^1.0.0"
  }
}
@cwellsx
Copy link
Author

cwellsx commented Oct 29, 2022

I get the same error above trying to start the typescript template:

C:\Users\Christopher\Source\Repos\trash>yarn create electron-app test2 --template=typescript-webpack
yarn create v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "create-electron-app@1.0.0" with binaries:
      - create-electron-app
√ Initializing Project Directory
√ Initializing Git repository
√ Locating custom template: "typescript-webpack"
√ Copying Starter Files
√ Initializing NPM Module
√ Setting up Forge configuration
√ Setting up TypeScript configuration
√ Installing Template Dependencies
√ Installing NPM Dependencies
Done in 97.56s.

C:\Users\Christopher\Source\Repos\trash>cd test2

C:\Users\Christopher\Source\Repos\trash\test2>npm run start

> test2@1.0.0 start
> electron-forge start

√ Checking your system
√ Locating Application

An unhandled rejection has occurred inside Forge:
Error: package.json for app does not have any devDependencies

Electron Forge was terminated. Location

@erikian
Copy link
Member

erikian commented Oct 29, 2022

Oddly, when I do a fresh install with yarn create electron-app test2 --template=webpack on Windows, it pins plugin-webpack to 6.0.0-beta.64, not 6.0.0-beta.69 as OP. So the version I'm getting is also wrong, but different:

{
  "name": "test2",
  "productName": "test2",
  "version": "1.0.0",
  "description": "My Electron application description",
  "main": ".webpack/main",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "lint": "echo \"No linting configured\""
  },
  "keywords": [],
  "license": "MIT",
  "config": {
    "forge": {
      "packagerConfig": {},
      "makers": [
        {
          "name": "@electron-forge/maker-squirrel",
          "config": {
            "name": "test2"
          }
        },
        {
          "name": "@electron-forge/maker-zip",
          "platforms": [
            "darwin"
          ]
        },
        {
          "name": "@electron-forge/maker-deb",
          "config": {}
        },
        {
          "name": "@electron-forge/maker-rpm",
          "config": {}
        }
      ],
      "plugins": [
        [
          "@electron-forge/plugin-webpack",
          {
            "mainConfig": "./webpack.main.config.js",
            "renderer": {
              "config": "./webpack.renderer.config.js",
              "entryPoints": [
                {
                  "html": "./src/index.html",
                  "js": "./src/renderer.js",
                  "name": "main_window",
                  "preload": {
                    "js": "./src/preload.js"
                  }
                }
              ]
            }
          }
        ]
      ]
    }
  },
  "devDependencies": {
    "@electron-forge/cli": "^6.0.0-beta.64",
    "@electron-forge/maker-deb": "^6.0.0-beta.64",
    "@electron-forge/maker-rpm": "^6.0.0-beta.64",
    "@electron-forge/maker-squirrel": "^6.0.0-beta.64",
    "@electron-forge/maker-zip": "^6.0.0-beta.64",
    "@electron-forge/plugin-webpack": "6.0.0-beta.64",
    "@vercel/webpack-asset-relocator-loader": "1.7.0",
    "css-loader": "^6.0.0",
    "electron": "21.2.0",
    "node-loader": "^2.0.0",
    "style-loader": "^3.0.0"
  },
  "dependencies": {
    "electron-squirrel-startup": "^1.0.0"
  }
}

I'm getting a different error because of the old plugin syntax used in beta-64:

PS E:\Documents\Erik\New folder\test2> yarn start
yarn run v1.22.5
$ electron-forge start
√ Checking your system
√ Locating Application

An unhandled rejection has occurred inside Forge:
Error: Expected plugin to either be a plugin instance or a { name, config } object but found @electron-forge/plugin-webpack,[object Object]

Electron Forge was terminated. Location:
{}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@VerteDinde
Copy link
Member

@cwellsx @erikian Thanks for the bug report and investigation! Will look into this - this specific error should have been fixed with the release of beta.70, so the older versions installing may well be in the issue 🤔

@VerteDinde VerteDinde added bug plugin/webpack Issues or pull requests related to first-party webpack plugins/templates template labels Oct 30, 2022
@cwellsx
Copy link
Author

cwellsx commented Oct 31, 2022

I tried again just now: and the version installed according to package.json is still beta.69.

@richardabear
Copy link

Hi guys, any manual fixes for the time being?

@VerteDinde
Copy link
Member

@richardabear The manual fix here should be making sure each @electron-forge dependency is correctly set to latest (6.0.0-beta.70 currently). We'll figure out why that's not updating correctly.

@VerteDinde
Copy link
Member

@cwellsx @erikian I've tried to repro on several different computers, and the version is consistently being returned as 6.0.0-beta.70 🤔 Sorry, could you both let me know if you have a global install of electron-forge (npm list -g), try blowing that away, and then re-initing a project?

It does seem that when all dependencies are set to beta.70, the yarn commands work as expected; I'm just trying to figure out why you're both seeing different versions of the wrong version.

@erikian
Copy link
Member

erikian commented Oct 31, 2022

No global electron-forge here:

image

@erikian
Copy link
Member

erikian commented Oct 31, 2022

@VerteDinde I found the issue. When create-electron-app is installed, it installs forge as a dependency. When create-electron-app is run, it calls @electron-forge\cli\dist\electron-forge-init.js, which ultimately copies the package.json from create-electron-app's package.json and runs npm install / yarn install.

In other words: the forge version you get depends on when create-electron-app was first run on your system. The same applies for any other dependencies, like @vercel/webpack-asset-relocator-loader as you can see in the comments above. Since @electron-forge/plugin-webpack is pinned in the package.json, that specific (and probably outdated) version is always installed.

When I run create-electron-app on npm instead of Yarn, I get beta-59. You're getting the latest version because the computers you're testing on never ran create-electron-app before.

@erikian
Copy link
Member

erikian commented Oct 31, 2022

Just submitted #3030 which unpins the version, so the most recent one will be installed. This doesn't change the outdated versions in the package.json itself though, that seems to be a separate issue.

@XMLHexagram
Copy link

XMLHexagram commented Oct 31, 2022

As a hack, I find add this to package.json

{
  "config": {
    "forge":{}
  }
}

Can solve this problem.

More details, I think this is cause by resolve-dir function in core/utils, which will guess which package.json is the best match(the package.json has config.forge is the best match or the highest package.json is the best match one). This is great. But it does not adapt config file.

So when you use config file, resolve-dir will endless try to find upper package.json and use the most top level package.json as working package.json.

I think I fix this issue in #3029.

@cwellsx
Copy link
Author

cwellsx commented Oct 31, 2022

The manual fix here should be making sure each @electron-forge dependency is correctly set to latest (6.0.0-beta.70 currently).

I had hoped so. But doing that, and running npm install, doesn't fix the problem: I still have the same error. Perhaps my template itself needs updating? What does your package.json look like?

image

Sorry, could you both let me know if you have a global install of electron-forge

I don't think I have it:

image

@erikian
Copy link
Member

erikian commented Oct 31, 2022

@cwellsx try yarn global remove create-electron-app, then run yarn create electron-app test --template=webpack again

@XMLHexagram
Copy link

XMLHexagram commented Oct 31, 2022

@cwellsx Could you try my fix ? This works on my machine.
image

@erickzhao erickzhao added initialization and removed plugin/webpack Issues or pull requests related to first-party webpack plugins/templates labels Oct 31, 2022
@MarshallOfSound
Copy link
Member

Fixed in b5d0587

@cwellsx
Copy link
Author

cwellsx commented Oct 31, 2022

try yarn global remove create-electron-app, then run yarn create electron-app test --template=webpack again

That installed "@electron-forge/cli": "^6.0.0-beta.70" but I have the same error on npm start.

Could you try my fix ? This works on my machine.

This displays a different error:

image

When I add this then npm start is successful:
image

The idea for doing that comes from the second list-item of https://www.electronforge.io/configuration which says, "a relative path":

Electron Forge configuration is centralized in a single configuration object. You can specify this config in your package.json on the config.forge property. This property can have be in one of two forms:

  • An object containing your entire Forge configuration.
  • A relative path pointing at a JavaScript file that exports your config.

@DERRICK-TORKORNOO
Copy link

app@1.0.0 start
electron-forge start

√ Checking your system
√ Locating application
√ Locating application
× Loading configuration
› Cannot find module 'electron-winstaller'
Require stack:

  • C:\Users\derri\OneDrive\Documents\electron-2\app\node_m…
    ■ Preparing native dependencies
    ■ Running generateAssets hook

An unhandled rejection has occurred inside Forge:
Error: Cannot find module 'electron-winstaller'
Require stack:

  • C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules@electron-forge\maker-squirrel\dist\MakerSquirrel.js
  • C:\Users\derri\OneDrive\Documents\electron-2\app\forge.config.ts
  • C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules@electron-forge\core\dist\util\forge-config.js
  • C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules@electron-forge\core\dist\util\index.js
  • C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules@electron-forge\core\dist\api\index.js
  • C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules@electron-forge\cli\dist\electron-forge-start.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules@cspotcode\source-map-support\source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object. (C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules@electron-forge\maker-squirrel\src\MakerSquirrel.ts:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions. [as .js] (C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules\ts-node\src\index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object. (C:\Users\derri\OneDrive\Documents\electron-2\app\forge.config.ts:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (C:\Users\derri\OneDrive\Documents\electron-2\app\node_modules\ts-node\src\index.ts:1618:23)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants