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

capacitor.config.json does not exist, did you setup capacitor in your project root? #259

Closed kimindu closed 11 months ago

kimindu commented 11 months ago

in capacitor 5.2.1 An error occurs as follows.

npx cap add @capacitor-community/electron

### ⠋ Adding Electron platformError: capacitor.config.json does not exist, did you setup capacitor in your project root? ✖ Adding Electron platform: capacitor.config.json does not exist, did you setup capacitor in your project root? C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:6 "use strict";Object.defineProperty(exports,"esModule",{value:!0}),exports.doAdd=void 0;const e=require("fs"),t=require("fs-extra"),r=require("path"),o=require("./common");function a(){const t=o.getCwd(),a={errorText:null,usersProjectCapConfigPath:null,srcTemplatePath:null,destTemplatePath:null,webAppPath:null},n=r.join(t,"capacitor.config.json"),i=r.join(dirname,"../","template"),s=r.join(t,"electron");if(e.existsSync(n)){const c=o.readJSON(n);if(c.webDir){const o=r.join(t,c.webDir);e.existsSync(o)?e.existsSync(s)?a.errorText="Electron platform already exists.":(a.destTemplatePath=s,a.srcTemplatePath=i,a.usersProjectCapConfigPath=n,a.webAppPath=o):a.errorText="WebDir defined in capacitor.config.json does not exist, did you build your webapp?"}else a.errorText="No webDir defined in capacitor.config.json."}else a.errorText="capacitor.config.json does not exist, did you setup capacitor in your project root?";return a}async function n(){const n=a();if(null!==n.errorText)throw o.errorLog(n.errorText),new Error(n.errorText);try{e.mkdirSync(n.destTemplatePath,{recursive:!0}),t.copySync(n.srcTemplatePath,n.destTemplatePath),e.renameSync(r.join(n.destTemplatePath,"gitignore"),r.join(n.destTemplatePath,".gitignore")),t.copySync(n.usersProjectCapConfigPath,r.join(n.destTemplatePath,"capacitor.config.json"));const a=o.readJSON(r.join(n.destTemplatePath,"capacitor.config.json")).appName,s=o.readJSON(r.join(n.destTemplatePath,"package.json"));s.name=a,o.writePrettyJSON(r.join(n.destTemplatePath,"package.json"),s),t.copySync(n.webAppPath,r.join(n.destTemplatePath,"app")),await o.runExec(cd ${n.destTemplatePath.replace(/ /g,"\\ ")} && npm i)}catch(i){throw o.errorLog(i.message),i}}exports.doAdd=n;

         ^

Error: capacitor.config.json does not exist, did you setup capacitor in your project root? at Object.n [as doAdd] (C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:6:1016) at C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:12:363 at Object.g [as runTask] (C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:2:1902) at i (C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:12:311) at C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:12:718 at parcelRequire.Focm../common (C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:12:915) at f (C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:1:468) at parcelRequire.FoEN (C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:1:771) at Object. (C:\01_DEVELOPE\node_pro\kdc_plugin\KDCReader\node_modules\@capacitor-community\electron\dist\cap-scripts.js:1:1023) at Module._compile (node:internal/modules/cjs/loader:1256:14)

kapiziak commented 11 months ago

Did you run cap init? Through for ex. npx cap init

kimindu commented 11 months ago

Yes, this will create a capacitor.config.ts. So, I created a capacitor.config.json.

Nevertheless, the same error occurs.

I checked.

I modified it as below cap-scripts.js. Installation completed successfully. function i() { const r = process.env.INIT_CWD; return e.join(r) //return e.join(r, "../", "../", "../") }

Now we have the next question, and let's create a new issue.

kimindu commented 11 months ago

npm i @capacitor-community/electron@5.0.0-next.3 is fix.