Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Karma plugin is meant to be used from within Angular CLI and will not work correctly outside of it #43

Closed
arcovoltaico opened this issue Jan 22, 2020 · 1 comment
Labels

Comments

@arcovoltaico
Copy link

arcovoltaico commented Jan 22, 2020

Hi,
I have trying many many configurations unsuccessfully. The one detailed below, throws an error when I am executing karma start.
arma plugin is meant to be used from within Angular CLI and will not work correctly outside of it

My package.json:

  "main": "main.js",
  "private": true,
  "scripts": {
    "postinstall": "npm run postinstall:electron && npx electron-builder install-app-deps",
    "postinstall:web": "node postinstall-web",
    "postinstall:electron": "node postinstall",
    "ng": "ng",
    "start": "npm run postinstall:electron && npm-run-all -p ng:serve electron:serve",
    "build": "npm run postinstall:electron && npm run electron:serve-tsc && ng build",
    "build:dev": "npm run build -- -c dev",
    "build:prod": "npm run build -- -c production",
    "ng:serve": "ng serve",
    "ng:serve:web": "npm run postinstall:web && ng serve -o",
    "electron:serve-tsc": "tsc -p tsconfig-serve.json",
    "electron:serve": "wait-on http-get://localhost:4200/ && npm run electron:serve-tsc && electron . --serve",
    "electron:local": "npm run build:prod && electron .",
    "electron:linux": "npm run build:prod && npx electron-builder build --linux",
    "electron:windows": "npm run build:prod && npx electron-builder build --windows",
    "electron:mac": "npm run build:prod && npx electron-builder build --mac",
    "test": "npm run postinstall:web && ng test",
    "e2e": "npm run postinstall:web && ng e2e"
  },
  "dependencies": {
    "@angular/animations": "^7.1.3",
    "@angular/cdk": "~7.3.7",
    "@angular/material": "^7.3.7",
    "@angular/platform-server": "^7.1.3",
    "angular2-fontawesome": "^5.2.1",
    "class-transformer": "^0.2.3",
    "electron": "^7.1.9",
    "electron-json-storage": "^4.1.6",
    "electron-simple-updater": "^1.5.0",
    "electron-window-state-manager": "^0.3.2",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "karma-electron": "^6.3.0",
    "karma-electron-launcher": "^0.2.0",
    "ngx-mat-select-search": "^1.8.0",
    "ngx-webstorage": "^2.0.1",
    "ngx-youtube-player": "^7.1.1",
    "pusher-js": "^5.0.0",
    "reflect-metadata": "^0.1.13",
    "require-context": "^1.1.0",
    "rxjs-compat": "^6.3.3",
    "shelljs": "^0.8.3",
    "tslib": "^1.9.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.13.0",
    "@angular/cli": "^7.1.3",
    "@angular/common": "^7.1.3",
    "@angular/compiler": "^7.1.3",
    "@angular/compiler-cli": "^7.1.3",
    "@angular/core": "^7.1.3",
    "@angular/forms": "^7.1.3",
    "@angular/http": "^7.1.3",
    "@angular/language-service": "^7.1.3",
    "@angular/platform-browser": "^7.1.3",
    "@angular/platform-browser-dynamic": "^7.1.3",
    "@angular/router": "^7.1.3",
    "@ngx-translate/core": "10.0.1",
    "@ngx-translate/http-loader": "3.0.1",
    "@types/jasmine": "^3.3.8",
    "@types/jasminewd2": "2.0.3",
    "@types/node": "^10.14.13",
    "codelyzer": "^5.0.0",
    "core-js": "^2.6.1",
    "electron-builder": "^21.1.5",
    "electron-reload": "^1.4.1",
    "jasmine-core": "^3.4.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^2.0.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "npm-run-all": "4.1.3",
    "npx": "10.2.0",
    "protractor": "^5.4.1",
    "rxjs": "^6.3.3",
    "rxjs-tslint": "^0.1.6",
    "ts-node": "6.0.3",
    "tslint": "^5.12.0",
    "typescript": "3.1.6",
    "wait-on": "2.1.0",
    "webdriver-manager": "12.0.6",
    "webpack": "^4.27.1",
    "zone.js": "^0.8.26"
  }
}

At project level I have this karma.config.js

module.exports = require('./src/karma.conf.js');
pointing to:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-electron'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['AngularElectron'],
    singleRun: true,
    customLaunchers: {
      AngularElectron: {
        base: 'Electron',
        browserWindowOptions: {
          webPreferences: {
            nodeIntegration: true,
            allowRunningInsecureContent: true
          }
        }
      }
    },
    client: {
      useIframe: false
    }
  });
}; 
@twolfson
Copy link
Owner

I'm pretty confident this error is coming from @angular-devkit packages in karma.conf (if have doubts, I recommend using grep with the error message)

Based on what it says, it seems like the package wants to use ng test instead of karma start (I'm guessing ng test will wrap karma start):

https://angular.io/cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants