简体   繁体   English

Angular 6和业力“无法加载“ @ angular-devkit / build-angular”,未注册”

[英]Angular 6 and karma 'Can not load “@angular-devkit/build-angular”, it is not registered'

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! 14 04 2018 14:17:00.453:ERROR [预处理]:无法加载“ @ angular-devkit / build-angular”,未注册! 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; ... \\ 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. ^ TypeError:无法在初始化时读取未定义的属性'options'(... \\ parkandrest-ui \\ node_modules \\ @ angular-devkit \\ build-angular \\ src \\ angular-cli-files \\ plugins \\ packages \\ angular_devkit \\ build_angular \\ src Array.invoke处的\\ angular-cli-files \\ plugins \\ karma.ts:52:39(... \\ parkandrest-ui \\ node_modules \\ di \\ lib \\ injector.js:75:15)在Injector.get(。 .. \\ parkandrest-ui \\ node_modules \\ di \\ lib \\ injector.js:48:43)在E:\\ Workspace \\ Training \\ spring-boot-tutorial \\ parkandrest-ui \\ node_modules \\ karma \\ lib \\ server.js:166 :20在Array.forEach()在Server._start(... \\ parkandrest-ui \\ node_modules \\ karma \\ lib \\ server.js:165:21)在Injector.invoke(... \\ parkandrest-ui \\ node_modules \\位于对象的Server.start上的di \\ lib \\ injector.js:75:15)(... \\ parkandrest-ui \\ node_modules \\ karma \\ lib \\ server.js:126:18)。

My karma.conf.js file looks like this: 我的karma.conf.js文件如下所示:

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. 当然会安装@ angular-devkit \\ build-angular。 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. 首先,我将整个项目更新为稳定的angular 6版本。 Next, I generated empty project like @R.Richards suggested and then I replaced almost every configuration in my old project with the new one. 接下来,我生成了一个空项目,如@ R.Richards建议,然后用新项目替换了旧项目中的几乎所有配置。 Finally, I have encountered a problem @Suvendu warn me about. 最后,我遇到了一个问题@Suvendu警告我。 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. 不幸的是,我的环境仍然存在一个问题(Intellij IDEA 2017.3.4 Ultimate),这使我无法直接从IDE启动业力测试(我遇到@Suvendu提到的相同错误),但这是一个主题下一个问题。

My solution was a little different, as I had to move the karma.conf.js. 我的解决方案有所不同,因为我不得不移动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 如果尚未完成:用karma.conf.js中的@angular-devkit/build-angular替换每次出现的@angular/cli
  3. Removing the files and the preprocessor configs from the karma.conf.js completely. 完全从karma.conf.js中删除filespreprocessor配置。 This is all defined in the angular.json and should be handled automatically by the @anguler-devkit karma plugin. 所有这些都在angular.json中定义,应该由@ anguler-devkit karma插件自动处理。

Could not find module "@angular-devkit/build-angular" 找不到模块“ @ angular-devkit / build-angular”

here is what worked for my project: 这是我的项目的工作方式:

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

I hope this works for you! 希望这对您有用!

Try installing karma-webpack with npm and then add it to the plugins array - 尝试使用npm安装karma-webpack,然后将其添加到插件数组-

 plugins: [
  ...
  require('karma-webpack'),
  ...
],

and replace the preprocessors with this - 并以此替换预处理器-

preprocessors: {
  './src/test.ts': ['webpack']
},

This worked in my case and will also work for the below anticipated future error- 就我而言,这是可行的,并且也可以解决以下预期的未来错误-

Error: The '@angular-devkit/build-angular/plugins/karma' karma plugin is meant to be used from within Angular CLI and will not work correctly outside of it. 错误:“ @ angular-devkit / build-angular / plugins / karma”业力插件应在Angular CLI中使用,在其外部无法正常使用。

Hope this helps. 希望这可以帮助。

我按照本指南进行了项目的干净迁移,为我解决了同样的问题。

The solution for me was that my NODE_ENV environmental variable was set to "production". 对我来说,解决方案是将我的NODE_ENV环境变量设置为“生产”。 While trying to upgrade to Angular 6 I did not realize that @angular-devkit/build-angular was listed in my devDependencies, which are not installed in a production environment. 在尝试升级到Angular 6时,我没有意识到在我的devDependencies中列出了@ angular-devkit / build-angular,但该产品未安装在生产环境中。

Running "unset NODE_ENV" and removing NODE_ENV from /etc/environment fixed my problem. 运行“ unset NODE_ENV”并从/ etc / environment中删除NODE_ENV解决了我的问题。 (Note: Be careful changing this variable in an actual production environment). (注意:在实际生产环境中,请小心更改此变量)。

In your karma.conf.js add following library, in plugins section. 在您的karma.conf.js中的“插件”部分中添加以下库。 This is done in Angular8. 这是在Angular8中完成的。

require('@angular-devkit/build-angular/plugins/karma')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块“@angular-devkit/build-angular” - Can not find module “@angular-devkit/build-angular” 错误:找不到模块'@angular-devkit/build-angular/package.json' - Error: Cannot find module '@angular-devkit/build-angular/package.json' 找不到“@angular-devkit/build-angular:browser”构建器的节点 package - Could not find the '@angular-devkit/build-angular:browser' builder's node package Npm 安装失败,节点 15(非 LTS)“@angular-devkit/build-angular”:“~0.1000.0” - Npm install fail with node 15 ( Not LTS ) "@angular-devkit/build-angular": "~0.1000.0" 发生未处理的异常:找不到模块“@angular-devkit/build-angular” - An unhandled exception occurred: Could not find module "@angular-devkit/build-angular" 无法使用ng服务找到模块“@ angular-devkit / build-angular” - Could not find module “@angular-devkit/build-angular” with ng serve 角度错误:未处理的异常:找不到模块@angular-devkit/build-angular/package.json - angular-error: unhandled exception: cannot find module @angular-devkit/build-angular/package.json 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js): - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js): 在 docker-compose 期间找不到模块 @angular-devkit/build-angular/package.json - Cannot find module @angular-devkit/build-angular/package.json during docker-compose up 发生未处理的异常:无法从“/ang-frontend”找到模块“@angular-devkit/build-angular”。 使用 docker 和 docker-compose - An unhandled exception occurred: Could not find module "@angular-devkit/build-angular" from "/ang-frontend". with docker and docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM