capacitor-community / electron

Deploy your Capacitor apps to Linux, Mac, and Windows desktops, with the Electron platform! 🖥️
https://capacitor-community.github.io/electron/
MIT License
318 stars 58 forks source link

Electron platform already exists trying to install #208

Closed philjones88 closed 1 year ago

philjones88 commented 1 year ago

Describe the bug

Unable to install

To Reproduce Steps to reproduce the behavior: Existing Ionic React app with some capacitor plugins for web.

Follow instructions at:

https://capacitor-community.github.io/electron/docs/gettingstarted

So using yarn so do yarn @capacitor-community/electron

This adds:

"@capacitor-community/electron": "^4.1.2",

To my dependencies in package.json.

Then do:

npx cap add @capacitor-community/electron

But hit:

npx cap add @capacitor-community/electron
✖ Adding Electron platform: Electron platform already exists.
/<redacted>/node_modules/@capacitor-community/electron/dist/cli-scripts/cap-scripts.js:6
`)}function ih(s){var t,e;return(e=(t=s.manifest)==null?void 0:t.electron)!=null&&e.src?(0,Xt.join)(s.rootPath,s.manifest.electron.src,"dist/plugin.js"):null}async function we(s,t){let e=require("ora"),i=require("chalk"),r=e(s).start(`${s}`);try{r=r.start(`${s}: ${i.dim("start \u{1F680}")}`);let n=process.hrtime(),o=await t(l=>{r=r.info(),r=r.start(`${s}: ${i.dim(l)}`)});r=r.info();let h=process.hrtime(n);return r=r.succeed(`${s}: ${i.dim("completed in "+tc(h))}`),o}catch(n){throw r=r.fail(`${s}: ${n.message?n.message:""}`),r=r.stop(),n}}var Qo=["s","ms","\u03BCp"];function tc(s){let t=s[0]+s[1]/1e9,e=0;for(;e<Qo.length-1&&!(t>=1);e++,t*=1e3);return t.toFixed(2)+Qo[e]}async function oh(s){let t=process.env.CAPACITOR_ROOT_DIR,e=(0,V.join)(t,"node_modules","@capacitor-community","electron","template.tar.gz"),i=(0,V.join)(t,"electron"),r,n,o={ts:(0,V.join)(t,"capacitor.config.ts"),js:(0,V.join)(t,"capacitor.config.js"),json:(0,V.join)(t,"capacitor.config.json")};(0,Qt.existsSync)(o.ts)?(r=o.ts,n="capacitor.config.ts"):(0,Qt.existsSync)(o.js)?(r=o.js,n="capacitor.config.js"):(r=o.json,n="capacitor.config.json");let h=JSON.parse(process.env.CAPACITOR_CONFIG);if((0,Qt.existsSync)(i))throw new Error("Electron platform already exists.");{(0,Qt.mkdirSync)(i),s("extracting template"),await(0,nh.extract)({file:e,cwd:i}),s("copying capacitor config file"),(0,rh.copySync)(r,(0,V.join)(i,n));let l=h.appName,a=vt((0,V.join)(i,"package.json")),c=vt((0,V.join)(t,"package.json"));a.name=l,c.repository&&(a.repository=c.repository),s("setting up electron project"),sh((0,V.join)(i,"package.json"),a),s("installing npm modules"),await Jt(`cd ${i} && npm i`)}}var hh=require("fs"),Ts=require("fs-extra"),ah=require("path");async function lh(s){let t=process.env.CAPACITOR_ROOT_DIR,e=process.env.CAPACITOR_WEB_DIR,i=(0,ah.join)(t,"electron","app");try{(0,hh.existsSync)(i)&&(0,Ts.removeSync)(i),s(`Copying ${e} into ${i}`),(0,Ts.copySync)(e,i)}catch(r){throw bs(r.message),r}}var ch=require("path");async function uh(s){let t=process.env.CAPACITOR_ROOT_DIR,e=(0,ch.join)(t,"electron");try{s("builing electron app"),s("running electron app"),await Jt(`cd ${e} && npm run electron:start-live`)}catch(i){throw bs(i.message),i}}var Re=require("fs"),fh=require("fs-extra"),T=require("path");async function dh(s){let t=process.env.CAPACITOR_ROOT_DIR,e=(0,T.join)(t,"package.json"),i=await vt(e),r=i.dependencies?i.dependencies:{},n=i.devDependencies?i.devDependencies:{},o=te(te({},r),n);s("searching for plugins");let l=(await eh(e)).map(d=>{let R=(()=>{if(o[d==null?void 0:d.id]){if(o[d.id].startsWith("file:")){let Ns=o[d==null?void 0:d.id].replace(/^file:/,""),ph=(0,T.isAbsolute)(Ns)?Ns:(0,T.resolve)(t,Ns);return(0,T.relative)((0,T.join)(t,"electron"),ph)}else if(o[d.id].match(/^(https?|git):/))return o[d.id]}return`${d==null?void 0:d.id}@${d==null?void 0:d.version}`})(),O=ih(d),_e=d==null?void 0:d.name,Oe=d==null?void 0:d.id;return{name:_e,path:O,installStr:R,id:Oe}}).filter(d=>d.path!==null),a="";s("generating electron-plugins.js");let c=(0,T.join)(t,"electron","src","rt"),u=`/* eslint-disable @typescript-eslint/no-var-requires */

Error: Electron platform already exists.
    at oh (/<redacted>/node_modules/@capacitor-community/electron/dist/cli-scripts/cap-scripts.js:6:1203)
    at /<redacted>/node_modules/@capacitor-community/electron/dist/cli-scripts/cap-scripts.js:15:219
    at we (/<redacted>/node_modules/@capacitor-community/electron/dist/cli-scripts/cap-scripts.js:6:325)
    at ec (/<redacted>/node_modules/@capacitor-community/electron/dist/cli-scripts/cap-scripts.js:15:180)
    at /<redacted>/node_modules/@capacitor-community/electron/dist/cli-scripts/cap-scripts.js:15:501
    at Object.<anonymous> (/<redacted>/node_modules/@capacitor-community/electron/dist/cli-scripts/cap-scripts.js:15:794)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)

Ok, hmm, maybe I did this in the past, git reset, try try just the npx cap add @capacitor-community/electron command but get:

npx cap add @capacitor-community/electron
[error] Platform @capacitor-community/electron not found.

So I have a Schrödinger's electron installation somehow? It is installed and not installed at the same time!? Expected behavior

Be able to install

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

node 16.17.0 npm 8.15.0 yarn 1.22.18 capacitor 4.3.0 ionic 6.2.7

capacitor.config.json:

{
  "appId": "com.my.app",
  "appName": "My App",
  "webDir": "build",
  "bundledWebRuntime": false
}

ionic.config.json:

{
  "name": "my-app",
  "integrations": {
    "capacitor": {}
  },
  "type": "react"
}

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

philjones88 commented 1 year ago

The electron folder existed already it seemed but was git ignored. My mistake!