Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 and karma 'Can not load "@angular-devkit/build-angular", it is not registered'

Tags:

I had to migrate to the newest angular version. After that, karma tests stopped working and just keep crushing with an error log:

14 04 2018 14:17:00.453:ERROR [preprocess]: Can not load "@angular-devkit/build-angular", it is not registered! Perhaps you are missing some plugin?

...\parkandrest-ui\node_modules\@angular-devkit\build-angular\src\angular-cli-files\plugins\packages\angular_devkit\build_angular\src\angular-cli-files\plugins\karma.ts:52 const options = config.buildWebpack.options; ^ TypeError: Cannot read property 'options' of undefined at init (...\parkandrest-ui\node_modules\@angular-devkit\build-angular\src\angular-cli-files\plugins\packages\angular_devkit\build_angular\src\angular-cli-files\plugins\karma.ts:52:39) at Array.invoke (...\parkandrest-ui\node_modules\di\lib\injector.js:75:15) at Injector.get (...\parkandrest-ui\node_modules\di\lib\injector.js:48:43) at E:\Workspace\Training\spring-boot-tutorial\parkandrest-ui\node_modules\karma\lib\server.js:166:20 at Array.forEach () at Server._start (...\parkandrest-ui\node_modules\karma\lib\server.js:165:21) at Injector.invoke (...\parkandrest-ui\node_modules\di\lib\injector.js:75:15) at Server.start (...\parkandrest-ui\node_modules\karma\lib\server.js:126:18) at Object.

My karma.conf.js file looks like this:

module.exports = function (config) {   config.set({     basePath: '',     frameworks: ['jasmine', '@angular-devkit/build-angular'],     plugins: [       require('karma-jasmine'),       require('karma-chrome-launcher'),       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     },     files: [       { pattern: './src/test.ts', watched: false }     ],     preprocessors: {       './src/test.ts': ['@angular-devkit/build-angular']     },     mime: {       'text/x-typescript': ['ts','tsx']     },     coverageIstanbulReporter: {       dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],       fixWebpackSourcePaths: true     },     angularCli: {       config: './angular.json',       environment: 'dev'     },     reporters: config.angularCli && config.angularCli.codeCoverage               ? ['progress', 'coverage-istanbul']               : ['progress', 'kjhtml'],     port: 9876,     colors: true,     logLevel: config.LOG_INFO,     autoWatch: true,     browsers: ['Chrome'],     singleRun: false   }); }; 

@angular-devkit\build-angular is of course installed. I appreciate any help.

EDIT: I have a solution which actually combines most of the user answers to my question with my own. Firstly I updated my whole project to stable angular 6 release. Next, I generated empty project like @R.Richards suggested and then I replaced almost every configuration in my old project with the new one. Finally, I have encountered a problem @Suvendu warn me about. I used his solution to resolve it. Unfortunately, I still have one problem with my environment (Intellij IDEA 2017.3.4 Ultimate) which disallows me to start karma tests directly from my IDE ( I've got the same error @Suvendu mentions about), however, it is a topic for the next question.

like image 633
pokemzok Avatar asked Apr 14 '18 12:04

pokemzok


People also ask

Can't find module angular Devkit build angular?

To solve the error "Could not find module '@angular-devkit/build-angular'", make sure to install the package by opening your terminal in your project's root directory and running the following command: npm i -D @angular-devkit/build-angular and restart your IDE and development server. Copied!

What is angular Devkit?

Angular CLI, Angular Schematics, and Angular DevKit DevKit was built to provide libraries that can be used to manage, develop, deploy, and analyze your code. DevKit has a schematics-cli command line tool that you can use to create your own Schematics.

How do I uninstall angular Devkit?

How do I uninstall Angular dev kit? If you still have the problem, please run npm i @angular-devkit/schematics , and after the update project, you can remove @angular-devkit/schematics from your package. json file, and then again delete node_modules folder and package-lock.


2 Answers

My solution was a little different, as I had to move the karma.conf.js.

  1. Update all dependencies and make sure the app itself works as intented
  2. If not done already: Replacing every occurrence of @angular/cli with @angular-devkit/build-angular in the karma.conf.js
  3. Removing the files and the preprocessor configs from the karma.conf.js completely. This is all defined in the angular.json and should be handled automatically by the @anguler-devkit karma plugin.
like image 170
hugo der hungrige Avatar answered Sep 17 '22 01:09

hugo der hungrige


Could not find module "@angular-devkit/build-angular"

here is what worked for my project:

  1. npm install -g @angular/cli
  2. npm install @angular/cli
  3. ng update @angular/cli --migrate-only --from=1.7.0
  4. ng update @angular/core
  5. npm install rxjs-compat
  6. ng serve

I hope this works for you!

like image 37
Esteban Contreras Avatar answered Sep 18 '22 01:09

Esteban Contreras