ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.17k stars 1.01k forks source link

bug: Several TS errors with capacitor dependencies; build fail #4646

Closed davicedraz closed 3 years ago

davicedraz commented 3 years ago

Bug Report

Capacitor Version

@capacitor/cli 2.0.0

@capacitor/core 2.0.0

@capacitor/ios 2.0.0

@capacitor/android 2.0.0

Platform(s)

Current Behavior

The error output (see below) when running ionic build. No changes were made to the source code, a build was successful only a few days ago. When executing rm -rf node_modules && rm package-lock.json && npm install in a local repository (which already has the dependencies downloaded) the error happens.

Expected Behavior

Should build successfully with ionic build or ng run app:build.

Code Reproduction

Create a project with the same dependencies and try to build it.

Other Technical Details

npm --version output: 6.14.4

node --version output: v12.17.0

pod --version output (iOS issues only):

Additional Context

ionic buildoutput:

> ng run app:build
  ng:analytics getGlobalAnalytics +0ms
  ng:analytics Client Analytics config found: false +75ms
  ng:analytics Analytics disabled. Ignoring all analytics. +0ms
  ng:analytics getSharedAnalytics +0ms
Browserslist: caniuse-lite is outdated. Please run next command `npm update`

chunk {main} main.js, main.js.map (main) 641 bytes [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 149 kB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 531 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 136 kB [initial] [rendered]
Date: 2021-05-28T12:13:00.543Z - Hash: 641061026299da672097 - Time: 5266ms

ERROR in node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/core-plugins.d.ts:1:13 - error TS1005: '=' expected.

1 import type { Plugin } from './definitions';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/core-plugins.d.ts:1:29 - error TS1005: ';' expected.

1 import type { Plugin } from './definitions';
                              ~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/definitions.d.ts:1:13 - error TS1005: '=' expected.

1 import type { PluginRegistry } from './legacy/legacy-definitions';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/definitions.d.ts:1:37 - error TS1005: ';' expected.

1 import type { PluginRegistry } from './legacy/legacy-definitions';
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/definitions.d.ts:2:13 - error TS1005: '=' expected.

2 import type { CapacitorException } from './util';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/definitions.d.ts:2:41 - error TS1005: ';' expected.

2 import type { CapacitorException } from './util';
                                          ~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/global.d.ts:1:13 - error TS1005: '=' expected.

1 import type { WebPlugin } from './web-plugin';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/global.d.ts:1:32 - error TS1005: ';' expected.

1 import type { WebPlugin } from './web-plugin';
                                 ~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:1:1 - error TS1128: Declaration or statement expected.

1 export type { CapacitorGlobal, PermissionState, Plugin, PluginCallback, PluginImplementations, PluginListenerHandle, PluginResultData, PluginResultError, } from './definitions';
  ~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:1:13 - error TS1005: ';' expected.

1 export type { CapacitorGlobal, PermissionState, Plugin, PluginCallback, PluginImplementations, PluginListenerHandle, PluginResultData, PluginResultError, } from './definitions';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:1:155 - error TS1109: Expression expected.

1 export type { CapacitorGlobal, PermissionState, Plugin, PluginCallback, PluginImplementations, PluginListenerHandle, PluginResultData, PluginResultError, } from './definitions';
                                                                                                                                                            ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:1:162 - error TS1005: ';' expected.

1 export type { CapacitorGlobal, PermissionState, Plugin, PluginCallback, PluginImplementations, PluginListenerHandle, PluginResultData, PluginResultError, } from './definitions';
                                                                                                                                                                   ~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:6:1 - error TS1128: Declaration or statement expected.

6 export type { WebViewPath, WebViewPlugin } from './core-plugins';
  ~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:6:13 - error TS1005: ';' expected.

6 export type { WebViewPath, WebViewPlugin } from './core-plugins';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:6:49 - error TS1005: ';' expected.

6 export type { WebViewPath, WebViewPlugin } from './core-plugins';
                                                  ~~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:9:1 - error TS1128: Declaration or statement expected.

9 export type { CallbackID, CancellableCallback, ISODateString, PluginConfig, PluginRegistry, } from './legacy/legacy-definitions';
  ~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:9:13 - error TS1005: ';' expected.

9 export type { CallbackID, CancellableCallback, ISODateString, PluginConfig, PluginRegistry, } from './legacy/legacy-definitions';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:9:93 - error90m TS1109: Expression expected.

9 export type { CallbackID, CancellableCallback, ISODateString, PluginConfig, PluginRegistry, } from './legacy/legacy-definitions';
                                                                                              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/index.d.ts:9:100 - error TS1005: ';' expected.

9 export type { CallbackID, CancellableCallback, ISODateString, PluginConfig, PluginRegistry, } from './legacy/legacy-definitions';
                                                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/platforms.d.ts:1:13 - error TS1005: '=' expected.

1 import type { PluginImplementations } from './definitions';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/platforms.d.ts:1:44 - error TS1005: ';' expected.

1 import type { PluginImplementations } from './definitions';
                                             ~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/platforms.d.ts:2:13 - error TS1005: '=' expected.

2 import type { PluginHeader } from './definitions-internal';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/platforms.d.ts:2:35 - error TS1005: ';' expected.

2 import type { PluginHeader } from './definitions-internal';
                                    ~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/util.d.ts:1:13 - error TS1005: '=' expected.

1 import type { WindowCapacitor } from './definitions-internal';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/util.d.ts:1:38 - error TS1005: ';' expected.

1 import type { WindowCapacitor } from './definitions-internal';
                                       ~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/web-plugin.d.ts:1:13 - error TS1005: '=' expected.

1 import type { PluginListenerHandle, Plugin } from './definitions';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/web-plugin.d.ts:1:51 - error TS1005: ';' expected.

1 import type { PluginListenerHandle, Plugin } from './definitions';
                                                    ~~~~~~~~~~~~~~~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/web-plugin.d.ts:2:13 - error TS1005: '=' expected.

2 import type { CapacitorException } from './util';
              ~
node_modules/capacitor-secure-storage-plugin/node_modules/@capacitor/core/types/web-plugin.d.ts:2:41 - error TS1005: ';' expected.

2 import type { CapacitorException } from './util';
                                          ~~~~~~~~

[ERROR] An error occurred while running subprocess ng.

        ng run app:build exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.
  ionic:cli-framework:utils:process onBeforeExit handler: process.exit received +0ms
  ionic:cli-framework:utils:process onBeforeExit handler: running 1 functions +0ms
  ionic:cli-framework:utils:process onBeforeExit handler: exiting (exit code 1) +63ms

dependencies in package.json:

  "dependencies": {
    "@angular/animations": "^8.2.14",
    "@angular/common": "8.1.2",
    "@angular/core": "8.1.2",
    "@angular/forms": "8.1.2",
    "@angular/platform-browser": "8.1.2",
    "@angular/platform-browser-dynamic": "8.1.2",
    "@angular/router": "8.1.2",
    "@angular/service-worker": "8.1.2",
    "@capacitor/android": "^2.0.0",
    "@capacitor/core": "^2.0.0",
    "@capacitor/ios": "^2.0.0",
    "@ionic-native/badge": "^5.30.0",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/in-app-browser": "^5.19.1",
    "@ionic-native/onesignal": "^5.22.0",
    "@ionic-native/open-native-settings": "^5.17.1",
    "@ionic-native/sqlite": "^5.31.1",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^4.7.1",
    "@ng-toolkit/universal": "~7.1.2",
    "@ngxs/store": "^3.5.1",
    "@types/socket.io-client": "^1.4.32",
    "capacitor-secure-storage-plugin": "^0.3.1",
    "cordova-open-native-settings": "1.5.2",
    "cordova-plugin-android-permissions": "^1.0.2",
    "cordova-plugin-appsflyer-sdk": "^4.4.26",
    "cordova-plugin-badge": "^0.8.8",
    "cordova-plugin-inappbrowser": "^3.2.0",
    "cordova-plugin-screen-orientation": "^3.0.2",
    "cordova-sqlite-storage": "^5.1.0",
    "core-js": "2.5.4",
    "es6-promise-plugin": "4.2.2",
    "hammerjs": "^2.0.8",
    "mocha": "5.2.0",
    "mochawesome": "4.1.0",
    "mochawesome-merge": "2.0.1",
    "mochawesome-report-generator": "4.0.1",
    "ng-recaptcha": "^5.0.0",
    "onesignal-cordova-plugin": "2.11.2",
    "rxjs": "6.5.1",
    "socket.io-client": "^2.3.0",
    "subsink": "^1.0.1",
    "tslib": "1.9.0",
    "uuid": "^8.0.0",
    "zone.js": "0.9.1"
  },
davicedraz commented 3 years ago

Related to #4490 #4610

Ionitron commented 3 years ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

davicedraz commented 3 years ago

In our previous build (success) capacitor-secure-storage-plugin uses core-js 3.12.1 and the last build (failure) uses core-js 3.13.0. What indicates a transitive dependency problem. Although the package-lock.json is identical between the two builds, the '"core-js": "^3.4.1"' snippet inside others dependencies caused npm to update that dependency.

We were able to work around this problem by:

  1. Freezing the dependency versions of our project in production, removing the ^ from package.json
  2. Adding the command npm ci --registry=https://registry.npmjs.org/ to our build pipeline

After this, the build completed successfully. Apparently one of the first steps of npm ci (unlike npm install) is to delete the node_modules folder and do a clean install of the dependencies, in addition to considering the exact versions specified on package-lock.json

Ref: https://stackoverflow.com/questions/52499617/what-is-the-difference-between-npm-install-and-npm-ci

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.