Error during `npm install @nativescript/capacitor`
shirakaba opened this issue · comments
System
- macOS 10.15
- Node v16.1.0
- shell:
zsh
Initialising the repo
# Initialise Svelte web app
npx degit sveltejs/template svelte-app
cd svelte-app
# Install Capacitor:
npm install @capacitor/cli@latest @capacitor/core@latest @capacitor/android@latest @capacitor/ios@latest
# As discussed in https://github.com/NativeScript/capacitor-docs/issues/5, this extra
# step isn't in the NativeScript Capacitor instructions but is required.
npx cap init
# build at least once before adding platforms
npm run build
npx cap add android
npx cap add ios
npx cap sync
Installing @nativescript/capacitor
$ npm install @nativescript/capacitor
npm WARN deprecated xmldom@0.4.0: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
> fsevents@1.2.13 install /Users/jamie/Downloads/svelte-capacitor-app/node_modules/watchpack-chokidar2/node_modules/fsevents
> node install.js
(node:82724) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
(Use `node --trace-deprecation ...` to show where the warning was created)
SOLINK_MODULE(target) Release/.node
CXX(target) Release/obj.target/fse/fsevents.o
SOLINK_MODULE(target) Release/fse.node
> ejs@2.7.4 postinstall /Users/jamie/Downloads/svelte-capacitor-app/node_modules/ejs
> node ./postinstall.js
Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)
> @nativescript/webpack@4.1.0 postinstall /Users/jamie/Downloads/svelte-capacitor-app/node_modules/@nativescript/webpack
> node postinstall.js
Skipping postinstall artifacts! We assumed the @nativescript/webpack is installing devDependencies
> @nativescript/capacitor@1.0.0-beta.2 postinstall /Users/jamie/Downloads/svelte-capacitor-app/node_modules/@nativescript/capacitor
> node dist/esm/postinstall --action install
⚙️ @nativescript/capacitor installing...
ADDED: src/nativescript
UPDATED: package.json
ADDED: src/native-custom.d.ts
UPDATED: .gitignore
UPDATED: ios/App/App/AppDelegate.swift
✅ iOS Ready
✅ Android Ready
> @nativescript/core@8.0.6 postinstall /Users/jamie/Downloads/svelte-capacitor-app/src/nativescript/node_modules/@nativescript/core
> node cli-hooks/postinstall.js
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN nativescript@ No description
npm WARN nativescript@ No repository field.
npm WARN nativescript@ No license field.
added 24 packages from 47 contributors and audited 24 packages in 6.396s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
[!] Error: Cannot find module 'typescript/package.json' from '/Users/jamie/Downloads/svelte-capacitor-app/src/nativescript'
⭐ @nativescript/capacitor ⭐
🧠 Learn more: 👉 https://capacitor.nativescript.org/getting-started.html
npm WARN ts-node@9.1.1 requires a peer of typescript@>=2.7 but none is installed. You must install peer dependencies yourself.
npm WARN ts-patch@1.3.3 requires a peer of typescript@>2.7.0 but none is installed. You must install peer dependencies yourself.
npm WARN ts-loader@8.3.0 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
+ @nativescript/capacitor@1.0.0-beta.2
added 769 packages from 395 contributors and audited 945 packages in 67.785s
59 packages are looking for funding
run `npm fund` for details
found 13 vulnerabilities (1 low, 11 moderate, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
This catches my eye:
[!] Error: Cannot find module 'typescript/package.json' from '/Users/jamie/Downloads/svelte-capacitor-app/src/nativescript'
I'm not sure what the consequences of that failure are. I may try again in a moment with Node v14.6.0.
For comparison, here's what the installation looks like with Node v14.6.0 instead (same failure):
$ npm install @nativescript/capacitor
npm WARN deprecated xmldom@0.4.0: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
> fsevents@1.2.13 install /Users/jamie/Downloads/svelte-capacitor-app/node_modules/watchpack-chokidar2/node_modules/fsevents
> node install.js
SOLINK_MODULE(target) Release/.node
CXX(target) Release/obj.target/fse/fsevents.o
SOLINK_MODULE(target) Release/fse.node
> ejs@2.7.4 postinstall /Users/jamie/Downloads/svelte-capacitor-app/node_modules/ejs
> node ./postinstall.js
Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)
> @nativescript/webpack@4.1.0 postinstall /Users/jamie/Downloads/svelte-capacitor-app/node_modules/@nativescript/webpack
> node postinstall.js
Skipping postinstall artifacts! We assumed the @nativescript/webpack is installing devDependencies
> @nativescript/capacitor@1.0.0-beta.2 postinstall /Users/jamie/Downloads/svelte-capacitor-app/node_modules/@nativescript/capacitor
> node dist/esm/postinstall --action install
⚙️ @nativescript/capacitor installing...
ADDED: src/nativescript
UPDATED: package.json
ADDED: src/native-custom.d.ts
UPDATED: .gitignore
UPDATED: ios/App/App/AppDelegate.swift
✅ iOS Ready
✅ Android Ready
> @nativescript/core@8.0.6 postinstall /Users/jamie/Downloads/svelte-capacitor-app/src/nativescript/node_modules/@nativescript/core
> node cli-hooks/postinstall.js
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN nativescript@ No description
npm WARN nativescript@ No repository field.
npm WARN nativescript@ No license field.
added 24 packages from 47 contributors and audited 24 packages in 2.178s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
[!] Error: Cannot find module 'typescript/package.json' from '/Users/jamie/Downloads/svelte-capacitor-app/src/nativescript'
⭐ @nativescript/capacitor ⭐
🧠 Learn more: 👉 https://capacitor.nativescript.org/getting-started.html
npm WARN ts-node@9.1.1 requires a peer of typescript@>=2.7 but none is installed. You must install peer dependencies yourself.
npm WARN ts-patch@1.3.3 requires a peer of typescript@>2.7.0 but none is installed. You must install peer dependencies yourself.
npm WARN ts-loader@8.3.0 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
+ @nativescript/capacitor@1.0.0-beta.2
added 769 packages from 395 contributors and audited 945 packages in 41.691s
59 packages are looking for funding
run `npm fund` for details
found 13 vulnerabilities (1 low, 11 moderate, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
I had a similar error
$ npm install @nativescript/capacitor
npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated xmldom@0.4.0: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm ERR! code 1
npm ERR! path D:\Downloads\calculator\calculator\node_modules\@nativescript\capacitor
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node dist/esm/postinstall --action install
npm ERR! ⚙️ @nativescript/capacitor installing...
npm ERR! undefined:36
npm ERR! }
npm ERR! ^
npm ERR!
npm ERR! SyntaxError: Unexpected token } in JSON at position 1178
npm ERR! at JSON.parse (<anonymous>)
npm ERR! at addProjectManagedNativeScript (D:\Downloads\calculator\calculator\node_modules\@nativescript\capacitor\dist\esm\postinstall.js:128:39)
npm ERR! at Object.<anonymous> (D:\Downloads\calculator\calculator\node_modules\@nativescript\capacitor\dist\esm\postinstall.js:749:5)
npm ERR! at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR! at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR! at Module.load (node:internal/modules/cjs/loader:981:32)
npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:822:12) npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
npm ERR! at node:internal/main/run_main_module:17:47
Then I looked at the files
https://unpkg.com/browse/@nativescript/capacitor@1.0.0/dist/esm/postinstall.js
And I saw an error in tsconfig.json
, removed it and everything worked
I had a similar error
$ npm install @nativescript/capacitor npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. npm WARN deprecated xmldom@0.4.0: Deprecated due to CVE-2021-21366 resolved in 0.5.0 npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm ERR! code 1 npm ERR! path D:\Downloads\calculator\calculator\node_modules\@nativescript\capacitor npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node dist/esm/postinstall --action install npm ERR! ⚙️ @nativescript/capacitor installing... npm ERR! undefined:36 npm ERR! } npm ERR! ^ npm ERR! npm ERR! SyntaxError: Unexpected token } in JSON at position 1178 npm ERR! at JSON.parse (<anonymous>) npm ERR! at addProjectManagedNativeScript (D:\Downloads\calculator\calculator\node_modules\@nativescript\capacitor\dist\esm\postinstall.js:128:39) npm ERR! at Object.<anonymous> (D:\Downloads\calculator\calculator\node_modules\@nativescript\capacitor\dist\esm\postinstall.js:749:5) npm ERR! at Module._compile (node:internal/modules/cjs/loader:1101:14) npm ERR! at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) npm ERR! at Module.load (node:internal/modules/cjs/loader:981:32) npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:822:12) npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) npm ERR! at node:internal/main/run_main_module:17:47
Then I looked at the files
https://unpkg.com/browse/@nativescript/capacitor@1.0.0/dist/esm/postinstall.js
And I saw an error intsconfig.json
, removed it and everything worked
yeah removing the tsconfig works but i would need to remove it every time, i think the real issue is the way they handle this file in the postinstall script
This is still affecting v2.0.2.
There is a one-line fix:
//const tsConfigJson = JSON.parse(stripJsonComments(tsConfigContent));
const tsConfigJson = require('typescript').parseConfigFileTextToJson('tsconfig.json', tsConfigContent).config;
@akvadrako interesting, thank you for this; we'll publish a patch with that. Just need to check it with few other cases.
@akvadrako quick question, if you try installing with yarn add @nativescript/capacitor
vs. npm install, still same?
I don't see that error here (but I'm using yarn).
I didn't try with yarn, just npm. But it should be the same error if you have trailing commas, I mean like , }
or , ]
.
Using a fallback setup there since the original setup does work as-is as well.
2.0.3 contains the fix, thank you for the suggestion @akvadrako