首页 > 解决方案 > protractor + angular 6 库抛出错误:ReferenceError:未定义窗口

问题描述

我可以问你为什么我的应用程序可以与 ng serve 和 ng build 一起使用,但是如果我运行量角器,我的 e2e 测试会失败并显示此消息?

[16:35:07] I/launcher - Running 1 instances of WebDriver
[16:35:07] I/direct - Using ChromeDriver directly...
[16:35:13] E/launcher - Error: ReferenceError: window is not defined
    at Object.<anonymous> (\node_modules\ngx-bootstrap\bundles\webpack:\ngx-bootstrap.umd\webpack\universalModuleDefinition:10:2)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at \dist\sg-ng-core-components\bundles\sg-ng-core-components.umd.js:2:268
    at Object.<anonymous> (\dist\sg-ng-core-components\bundles\sg-ng-core-components.umd.js:5:2)

遵循 tsconfig.e2e

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/e2e",
    "module": "commonjs",
    "target": "es2017",
    "types": [
      "jasmine",
      "node"
    ]
  }
}

这是我的 tsconfig.app

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": [
      "node"
    ]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

标签: protractorangular-cling-packagr

解决方案


推荐阅读