INIT_CWD not always accurate in CLI
See original GitHub issueDescribe the bug Adding the platform results in a strange file-not-found error, although the file exists.
To Reproduce Steps to reproduce the behavior:
- Use rather recent Ionic templated app which generates web and apk builds nicely
- Run
npx cap add @capacitor-community/electron
- Get error about missing configuration
Expected behavior It should add the capacitor-community electron platform
Screenshots
➜ npx cap add @capacitor-community/electron
> @capacitor-community/electron@1.3.2 capacitor:add
> node dist/cap-scripts.js add
⠋ 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?
(node:4565) UnhandledPromiseRejectionWarning: Error: capacitor.config.json does not exist, did you setup capacitor in your project root?
at Object.n [as doAdd] (/home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:6:1016)
at /home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:12:363
at Object.g [as runTask] (/home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:2:1902)
at i (/home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:12:311)
at /home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:12:718
at Object.parcelRequire.Focm../common (/home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:12:915)
at f (/home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:1:468)
at parcelRequire.FoEN (/home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:1:771)
at Object.<anonymous> (/home/riot/src/isomer/isomer_modules/leerstandsmelder/leerstandsmelder-2/frontend/leerstandsmelder-ionic-ng-autoentities/node_modules/@capacitor-community/electron/dist/cap-scripts.js:1:1023)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
(node:4565) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:4565) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Desktop (please complete the following information):
- OS: Debian Sid
- Version:
- npm: 7.3.0
- ionic: 6.12.3
Additional context The capacitor configuration exists and has been used to add android and ios platforms already:
➜ cat capacitor.config.json
{
"appId": "de.foobar.app",
"appName": "foobar",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"plugins": {
"SplashScreen": {
"launchShowDuration": 0
}
},
"cordova": {}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:12 (3 by maintainers)
Top Results From Across the Web
npm-run-script
Description. This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts.
Read more >Questions & Answers | Yarn - Package Manager
A list of answers to commonly asked questions.
Read more >How to reference a project root directory in an npm script
If you want your script to use different behavior based on what subdirectory you're in, you can use the INIT_CWD environment variable, which...
Read more >Npm postinstall only on development - Stack Overflow
NPM sets an environment variable to "true" when install is run with --production. To only run the postinstall script if npm install was...
Read more >Docker as a Tool Provider - Stephen Cleary
This is all good, until you want to make use of some nifty Linux tools. The thing is, Windows just doesn't work so...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Facing exactly the same issue and the linked comment didn’t help.
The code [1] makes the search go 3 levels up, and so for me it’s looking for the config file in my home dir.
I am brand new to Node, but the workaround I found was to just set
INIT_CWD
to a dir 3 levels deep, in this case the electron dir that was already created:Running from within a child dir didn’t work.
To repro on a brand new system:
One guess could be that my capacitor version is 2.4.6, but the docs seem to require 2.3.0 (
Note: these instructions require a Capacitor version of ^2.3.0
)[1] https://github.com/capacitor-community/electron/blob/main/cap-scripts/common.ts#L49
I have installed today the plugin and have the same error:
capacitor.config.json does not exist
.I saw this issue and this comment and tried to declare the INIT_CWD env but the error still there. So I debugged the code and saw the INIT_CWD was returning the webapp folder and not the
node_modules/@capacitor-community/electron
folder.So I replaced
function i(){const r=process.env.INIT_CWD;return e.join(r,"../","../","../")}
for
function i(){const r=process.env.INIT_CWD;return e.join(r,"/")}
on
node_modules/@capacitor-community/electron/dist/cap-scripts.js
and it worked…I don’t know if this is because of node/npm version or because of macOs… So I have changed the
common.ts
and made a PR…I hope this can help others!