【问题标题】:The "path" argument must be of type string. Received type object - Angular 7“路径”参数必须是字符串类型。接收到的类型对象 - Angular 7
【发布时间】:2019-10-10 02:49:16
【问题描述】:

我尝试在我的 Angular 项目类型上运行测试

ng test --browsers=PhantomJS

之前,我必须使用命令手动安装 phantomjs

npm install phantomjs-prebuilt@2.1.16 -ignore-scripts

但是在ng test --br ...之后我收到了这个错误

23 05 2019 08:08:28.194:ERROR [config]: 配置文件错误! TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。接收到的类型对象 在 validateString (internal/validators.js:125:11) 在 Object.extname (path.js:1365:5) 在 phantomJSExePath (/gui-build/node_modules/karma-phantomjs-launcher/index.js:18:12) 在对象。 (/gui-build/node_modules/karma-phantomjs-launcher/index.js:107:12) 在 Module._compile (internal/modules/cjs/loader.js:701:30) 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) 在 Module.load (internal/modules/cjs/loader.js:600:32) 在 tryModuleLoad (internal/modules/cjs/loader.js:539:12) 在 Function.Module._load (internal/modules/cjs/loader.js:531:3) 在 Module.require (internal/modules/cjs/loader.js:637:17) 在需要 (internal/modules/cjs/helpers.js:22:18)....

我该如何解决这个问题?

环境:Angular CLI:7.3.9 节点:10.15.3 操作系统:linux x64 角度:7.2.15

karma.conf.js

 // Karma configuration
 // Generated on Wed Oct 24 2018 11:15:29 GMT+0200 (Central European Daylight Time)
 const path = require('path');

 module.exports = function(config) {
 config.set({
 files: [
  'src/**/*.js',
  'src/test/**/*.js'
 ],
 basePath: '',
 frameworks: ['jasmine'],

 preprocessors: {
  '!(test)/**/*.js': 'coverage'
 },

 plugins: [
  require('karma-jasmine'),
  require('karma-chrome-launcher'),
  require('karma-jasmine-html-reporter'),
  require('karma-coverage-istanbul-reporter'),
  require('@angular/cli/plugins/karma')
 ],

 client: {
  clearContext: false
 },

 coverageIstanbulReporter: {
  reports: [ 'html', 'lcovonly', 'text-summary' ],
  dir: path.join(__dirname, 'coverage'),
  skipFilesWithNoCoverage: true,
  fixWebpackSourcePaths: true
 },

 angularCli: {
  environment: 'dev',
  config: '@angular/cli'
 },

 // list of files to exclude
 exclude: [
 ],

 reporters: ['progress', 'kjhtml'], 
 port: 9876,
 colors: true,
 logLevel: config.LOG_INFO,
 autoWatch: false,
 browsers: ['Chrome'],
 singleRun: true,
 concurrency: Infinity
 })
} ;

package.json

{
 "name": "gui",
 "version": "0.0.0",
 "scripts": {
 "ng": "ng",
 "start": "ng serve",
 "build": "ng build",
 "release": "ng build --prod",
 "test": "ng test",
 "lint": "ng lint",
 "e2e": "ng e2e",
 "version": "git add -A package.json && git commit",
 "postversion": "rm -rf build/temp"
 },
 "private": true,
 "dependencies": {
 "@angular/animations": "^7.2.15",
 "@angular/common": "^7.2.15",
 "@angular/compiler": "^7.2.15",
 "@angular/core": "^7.2.15",
 "@angular/forms": "^7.2.15",
 "@angular/http": "^7.2.15",
 "@angular/platform-browser": "^7.2.15",
 "@angular/platform-browser-dynamic": "^7.2.15",
 "@angular/router": "^7.2.15",
 "@ng-bootstrap/ng-bootstrap": "^3.3.0",
 "core-js": "^2.5.4",
 "font-awesome": "^4.7.0",
 "intl": "^1.2.5",
 "lodash": "^4.17.11",
 "rxjs": "^6.5.2",
 "tslib": "^1.9.0",
 "zone.js": "~0.8.29"
 },
 "devDependencies": {
 "@angular-devkit/build-angular": "~0.13.0",
 "@angular/cli": "~7.3.9",
 "@angular/compiler-cli": "^7.2.15",
 "@angular/language-service": "^7.2.15",
 "@types/jasmine": "~2.8.6",
 "@types/jasminewd2": "~2.0.3",
 "@types/node": "~8.9.4",
 "codelyzer": "~4.2.1",
 "jasmine-core": "^2.99.1",
 "jasmine-spec-reporter": "^4.2.1",
 "karma": "^1.7.1",
 "karma-chrome-launcher": "^2.2.0",
 "karma-coverage-istanbul-reporter": "^2.0.4",
 "karma-jasmine": "^1.1.2",
 "karma-jasmine-html-reporter": "^0.2.2",
 "karma-phantomjs-launcher": "^1.0.4",
 "phantomjs-prebuilt": "^2.1.16",
 "protractor": "~5.3.0",
 "ts-node": "~5.0.1",
 "tslint": "~5.9.1",
 "typescript": "~3.2.4"
 }
}

我该如何解决?提前致谢

【问题讨论】:

标签: node.js angular npm phantomjs


【解决方案1】:

试试这个:

 browsers: ['Chrome', 'PhantomJS'],  // HERE MISSING 'PhantonJS'

karma.conf.js

 // Karma configuration
 // Generated on Wed Oct 24 2018 11:15:29 GMT+0200 (Central European Daylight Time)
 const path = require('path');

 module.exports = function(config) {
 config.set({
 files: [
  'src/**/*.js',
  'src/test/**/*.js'
 ],
 basePath: '',
 frameworks: ['jasmine'],

 preprocessors: {
  '!(test)/**/*.js': 'coverage'
 },

 plugins: [
  require('karma-jasmine'),
  require('karma-chrome-launcher'),
  require('karma-jasmine-html-reporter'),
  require('karma-coverage-istanbul-reporter'),
  require('@angular/cli/plugins/karma')
 ],

 client: {
  clearContext: false
 },

 coverageIstanbulReporter: {
  reports: [ 'html', 'lcovonly', 'text-summary' ],
  dir: path.join(__dirname, 'coverage'),
  skipFilesWithNoCoverage: true,
  fixWebpackSourcePaths: true
 },

 angularCli: {
  environment: 'dev',
  config: '@angular/cli'
 },

 // list of files to exclude
 exclude: [
 ],

 reporters: ['progress', 'kjhtml'], 
 port: 9876,
 colors: true,
 logLevel: config.LOG_INFO,
 autoWatch: false,
 browsers: ['Chrome', 'PhantomJS'],  // HERE MISSING 'PhantonJS'
 singleRun: true,
 concurrency: Infinity
 })
} ;

【讨论】:

    【解决方案2】:

    尝试重新安装 karma-phantomjs-launcher 和 phantomjs-prebuilt,它适用于我...

    【讨论】:

      【解决方案3】:

      我能够通过从 karma.conf.js 中删除 "karma-phantomjs-launcher" 来解决此问题

      注意:能够做到这一点,因为我们没有使用phantomjs,据我了解,它现在已经被弃用了一段时间。

      【讨论】:

      • 只是在同一个问题上运行。删除“require('karma-phantomjs-launcher')”确实起到了作用。感谢您的提示!
      猜你喜欢
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      • 1970-01-01
      • 2019-05-13
      • 2020-09-21
      • 2019-12-14
      相关资源
      最近更新 更多