capacitor: Transpile error after import capacitor/core

Description of the problem: I get a transpile error after import capacitor/core in the app.component.ts

Error:

Thomass-Mac-Pro:quest thomas$ ionic build

ionic-app-scripts build [15:14:32] ionic-app-scripts 3.2.2 [15:14:32] build dev started … [15:14:32] clean started … [15:14:32] clean finished in 5 ms [15:14:32] copy started … [15:14:32] deeplinks started … [15:14:32] deeplinks finished in 31 ms [15:14:32] transpile started … [15:14:37] typescript: node_modules/@capacitor/core/dist/esm/global.d.ts, line: 3 ‘=’ expected.

   L2:  declare var Capacitor: _Capacitor;
   L3:  declare const Plugins: import("./core-plugin-definitions").PluginRegistry;
   L4:  export { Capacitor, Plugins };

[15:14:37] typescript: node_modules/@capacitor/core/dist/esm/global.d.ts, line: 3 Cannot find name ‘import’.

   L2:  declare var Capacitor: _Capacitor;
   L3:  declare const Plugins: import("./core-plugin-definitions").PluginRegistry;
   L4:  export { Capacitor, Plugins };

[15:14:37] typescript: node_modules/@capacitor/core/dist/esm/global.d.ts, line: 3 Property ‘PluginRegistry’ does not exist on type ‘“./core-plugin-definitions”’.

   L2:  declare var Capacitor: _Capacitor;
   L3:  declare const Plugins: import("./core-plugin-definitions").PluginRegistry;
   L4:  export { Capacitor, Plugins };

[15:14:37] ionic-app-script task: “build” [15:14:37] Error: Failed to transpile program Error: Failed to transpile program at new BuildError (/Users/thomas/Documents/Again/quest/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28) at /Users/thomas/Documents/Again/quest/node_modules/@ionic/app-scripts/dist/transpile.js:159:20 at new Promise (<anonymous>) at transpileWorker (/Users/thomas/Documents/Again/quest/node_modules/@ionic/app-scripts/dist/transpile.js:107:12) at Object.transpile (/Users/thomas/Documents/Again/quest/node_modules/@ionic/app-scripts/dist/transpile.js:64:12) at /Users/thomas/Documents/Again/quest/node_modules/@ionic/app-scripts/dist/build.js:109:82 [ERROR] An error occurred while running subprocess ionic-app-scripts.

    ionic-app-scripts build exited with exit code 1.

    Re-running this command with the --verbose flag may provide more information.

Affected platform

  • Android
  • iOS
  • electron
  • web

OS of the development machine

  • Windows
  • macOS
  • linux

Other information: package.json file:

{
  "name": "quest",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@capacitor/android": "^1.0.0-beta.25",
    "@capacitor/cli": "1.0.0-beta.25",
    "@capacitor/core": "^1.0.0-beta.25",
    "@capacitor/ios": "^1.0.0-beta.25",
    "@ionic-native/core": "~4.20.0",
    "@ionic-native/splash-screen": "~4.20.0",
    "@ionic-native/status-bar": "~4.20.0",
    "@ionic/storage": "2.2.0",
    "ionic-angular": "3.9.5",
    "ionicons": "3.0.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.29"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.2",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project"
}

Capacitor version: 1.0.0-beta.25

node version: 10.15.3

npm version: 6.4.1

Steps to reproduce:

  1. ionic start quest blank --type=ionic-angular --capacitor
  2. ionic build
  3. npx cap copy
  4. add import { Plugins } from ‘@capacitor/core’; to app.component.ts
  5. ionic build

Fully ionic info:

Ionic:

ionic (Ionic CLI) : 4.12.0 (/usr/local/lib/node_modules/ionic) Ionic Framework : ionic-angular 3.9.5 @ionic/app-scripts : 3.2.2

Capacitor:

capacitor (Capacitor CLI) : 1.0.0-beta.25 @capacitor/core : 1.0.0-beta.25

System:

NodeJS : v10.15.3 (/usr/local/bin/node) npm : 6.4.1 OS : macOS High Sierra

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 29 (4 by maintainers)

Most upvoted comments

In Plugins -> global.d.ts This work for me

import { Capacitor as _Capacitor } from ‘./definitions’; import * as _Plugins from “./core-plugin-definitions”; declare const Capacitor: _Capacitor;

declare const Plugins: _Plugins.PluginRegistry; export { Capacitor, Plugins };

Try updating typescript to 2.9 or newer

i am facing same issue with capacitor 3, any solution ?

Other solution: upgrade your typescript version 3.7.2

Thanks @CarlosFJ It worked for me.

Thanks @CarlosFJ its works for me thanks man you save my day.

@jabiinfante I updated to 2.9.2 but now when I build in android with “ionic build --prod” shows me error: Cannot find module “.”

Is it just a warning or does something break? If everything works just ignore it. The example app uses compiler-cli 5.0.1 and it works fine, but I didn’t check it it shows the warning. No idea about updating to angular 6, sorry