electron-userland / electron-forge-templates

Templates bundled with Electron Forge <= 5 to create Electron apps using popular JavaScript frameworks
107 stars 23 forks source link

Cannot find namespace 'Electron' on new project #54

Closed nrlquaker closed 5 years ago

nrlquaker commented 7 years ago

Please describe your issue: Running lint on newly created typescript+react template gives warnings:

Error at src/index.ts:1:36: Cannot find module 'electron'.
Error at src/index.ts:7:17: Cannot find namespace 'Electron'.

*Console output when you run electron-forge init with the environment variable `DEBUG=electron-forge:`. (Instructions on how to do so here). Please include the stack trace if one exists.**

electron-forge init my-new-project --template=react-typescript
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:lifecycle Process Started: Checking your system +0ms
  electron-forge:lifecycle Process Succeeded: Checking your system +214ms
  electron-forge:runtime-config setting key: verbose to value: false +0ms
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:init Initializing in: /Users/user/Projects/my-new-project +0ms
  electron-forge:lifecycle Process Started: Initializing Project Directory +0ms
  electron-forge:init:directory creating directory: /Users/user/Projects/my-new-project +0ms
  electron-forge:lifecycle Process Succeeded: Initializing Project Directory +3ms
  electron-forge:lifecycle Process Started: Initializing Git Repository +1ms
  electron-forge:init:git executing "git init" in directory: /Users/user/Projects/my-new-project +0ms
  electron-forge:lifecycle Process Succeeded: Initializing Git Repository +18ms
  electron-forge:lifecycle Process Started: Copying Starter Files +1ms
  electron-forge:init:starter-files creating directory: /Users/user/Projects/my-new-project/src +0ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/tmpl/_gitignore" --> "/Users/user/Projects/my-new-project/.gitignore" +1ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/tmpl/_compilerc" --> "/Users/user/Projects/my-new-project/.compilerc" +5ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/tmpl/index.js" --> "/Users/user/Projects/my-new-project/src/index.js" +1ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/tmpl/index.html" --> "/Users/user/Projects/my-new-project/src/index.html" +1ms
  electron-forge:lifecycle Process Succeeded: Copying Starter Files +9ms
  electron-forge:lifecycle Process Started: Initializing NPM Module +0ms
  electron-forge:init:npm writing package.json to: /Users/user/Projects/my-new-project +0ms
  electron-forge:lifecycle Process Succeeded: Initializing NPM Module +6ms
  electron-forge:lifecycle Process Started: Installing NPM Dependencies +1ms
  electron-forge:init:npm installing dependencies +2ms
  electron-forge:dependency-installer installing ["electron-compile","electron-squirrel-startup"] in: /Users/user/Projects/my-new-project dev=false,exact=false,withYarn=false +0ms
  electron-forge:dependency-installer executing ["install","electron-compile","electron-squirrel-startup","--save"] in: /Users/user/Projects/my-new-project +0ms
  electron-forge:runtime-config fetching key verbose +0ms
  electron-forge:init:npm installing devDependencies +6s
  electron-forge:dependency-installer installing ["babel-preset-env","babel-preset-react","babel-plugin-transform-async-to-generator","electron-forge"] in: /Users/user/Projects/my-new-project dev=true,exact=false,withYarn=false +6s
  electron-forge:dependency-installer executing ["install","babel-preset-env","babel-preset-react","babel-plugin-transform-async-to-generator","electron-forge","--save-dev"] in: /Users/user/Projects/my-new-project +0ms
  electron-forge:runtime-config fetching key verbose +6s
  electron-forge:init:npm installing exact dependencies +30s
  electron-forge:dependency-installer installing ["electron-prebuilt-compile"] in: /Users/user/Projects/my-new-project dev=true,exact=true,withYarn=false +30s
  electron-forge:dependency-installer executing ["install","electron-prebuilt-compile","--save-exact","--save-dev"] in: /Users/user/Projects/my-new-project +0ms
  electron-forge:runtime-config fetching key verbose +30s
  electron-forge:init:npm not installing linting deps +16s
  electron-forge:lifecycle Process Succeeded: Installing NPM Dependencies +52s
  electron-forge:lifecycle Process Started: Locating custom template: "react-typescript" +2ms
  electron-forge:init:custom using local template +0ms
  electron-forge:lifecycle Process Succeeded: Locating custom template: "react-typescript" +3ms
  electron-forge:lifecycle Process Started: Installing Template Dependencies +1ms
  electron-forge:init:custom installing dependencies +1ms
  electron-forge:dependency-installer installing ["react@^15.4.1","react-dom@^15.4.1","@types/react@^0.14.55","@types/react-dom@^0.14.20","@types/electron-devtools-installer@^2.0.2","electron-devtools-installer@^2.1.0","react-hot-loader@^3.0.0-beta.6","tslib@^1.4.0"] in: /Users/user/Projects/my-new-project dev=false,exact=false,withYarn=false +16s
  electron-forge:dependency-installer executing ["install","react@^15.4.1","react-dom@^15.4.1","@types/react@^0.14.55","@types/react-dom@^0.14.20","@types/electron-devtools-installer@^2.0.2","electron-devtools-installer@^2.1.0","react-hot-loader@^3.0.0-beta.6","tslib@^1.4.0","--save"] in: /Users/user/Projects/my-new-project +0ms
  electron-forge:runtime-config fetching key verbose +16s
  electron-forge:init:custom installing devDependencies +8s
  electron-forge:dependency-installer installing ["tslint@^5.1.0","typescript@~2.2.2"] in: /Users/user/Projects/my-new-project dev=true,exact=false,withYarn=false +8s
  electron-forge:dependency-installer executing ["install","tslint@^5.1.0","typescript@~2.2.2","--save-dev"] in: /Users/user/Projects/my-new-project +0ms
  electron-forge:runtime-config fetching key verbose +8s
  electron-forge:lifecycle Process Succeeded: Installing Template Dependencies +14s
  electron-forge:lifecycle Process Started: Copying Template Files +1ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/node_modules/electron-forge-template-react-typescript/tmpl/_compilerc" --> "/Users/user/Projects/my-new-project/.compilerc" +1m
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/node_modules/electron-forge-template-react-typescript/tmpl/src/app.tsx" --> "/Users/user/Projects/my-new-project/src/app.tsx" +2ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/node_modules/electron-forge-template-react-typescript/tmpl/src/index.html" --> "/Users/user/Projects/my-new-project/src/index.html" +1ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/node_modules/electron-forge-template-react-typescript/tmpl/src/index.ts" --> "/Users/user/Projects/my-new-project/src/index.ts" +1ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/node_modules/electron-forge-template-react-typescript/tmpl/tsconfig.json" --> "/Users/user/Projects/my-new-project/tsconfig.json" +1ms
  electron-forge:init:starter-files copying "/usr/local/lib/node_modules/electron-forge/node_modules/electron-forge-template-react-typescript/tmpl/tslint.json" --> "/Users/user/Projects/my-new-project/tslint.json" +1ms
  electron-forge:lifecycle Process Succeeded: Copying Template Files +21ms

What command line arguments are you passing?

electron-forge init my-new-project --template=react-typescript

What does your config.forge data in package.json look like?

"forge": {
      "make_targets": {
        "win32": [
          "squirrel"
        ],
        "darwin": [
          "zip"
        ],
        "linux": [
          "deb",
          "rpm"
        ]
      },
      "electronPackagerConfig": {
        "packageManager": "npm"
      },
      "electronWinstallerConfig": {
        "name": "my_new_project"
      },
      "electronInstallerDebian": {},
      "electronInstallerRedhat": {},
      "github_repository": {
        "owner": "",
        "name": ""
      },
      "windowsStoreConfig": {
        "packageName": "",
        "name": "mynewproject"
      }
    }

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem.

Steps to reproduce: 1 . electron-forge init my-new-project --template=react-typescript

  1. cd my-new-project
  2. npm run lint

Installing electron package fixes this, but app works fine w/o. Just gives lint errors.

MarshallOfSound commented 7 years ago

@nrlquaker What version of npm / yarn are you using?

nrlquaker commented 7 years ago

@MarshallOfSound

npm -v
5.5.1
kavengagne commented 6 years ago

Having the exact same issue here. It also affects code completion in VS Code since it cannot find the "electron" module.

This happens because electron does not exist in the node_module folder. It does not seem to be required by electron-forge.

If I do npm install electron --save-dev, it fixes the issue.

One way to fix it would be to include electron in the react-typescript template's devDependencies.

nrlquaker commented 6 years ago

Any news?

utillity commented 6 years ago

same issue. would be great to have intellisense in VSCode and to get rid of the false error

severity: 'Error'
message: 'Cannot find module 'electron'.'
source: 'ts'
code: '2307'
GitFlip commented 6 years ago

@MarshallOfSound Have you given this any thought? Do you believe @kavengagne's solution can be used or is there another one that you are thinking about?

malept commented 5 years ago

Closing, see https://github.com/electron-userland/electron-forge-templates/issues/66