我试图运行量角器但是使用es2015模块为我的Angular 2应用程序转换打字稿。这适用于应用程序本身,但它与量角器失败。
在我的tsconfig中使用模块es2015时出现以下错误:
(node:9096) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[15:23:36] I/direct - Using ChromeDriver directly...
[15:23:36] I/launcher - Running 1 instances of WebDriver
[15:23:40] E/launcher - Error: C:\xxx\test1.e2e.ts:1
(function (exports, require, module, __filename, __dirname) { import { browser, element, by, $ } from 'protractor';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:78:16)
at Module._compile (module.js:543:28)
at Module.m._compile (C:\xxx\ts-node\src\index.ts:406:23)
at Module._extensions..js (module.js:580:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\vmob-apps\purple-chicken\node_modules\ts-node\src\index.ts:409:12)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
[15:23:40] E/launcher - Process exited with error code 100
这是我的tsconfig.json
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"target": "es5",
"mapRoot": "./",
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"sourceMap": true,
"typeRoots": [
"node_modules/@types"
],
"types": [
"jasmine",
"node"
],
"lib": [
"dom",
"es2015"
]
},
"exclude": [
"node_modules",
"dist",
"**/*.ngfactory.ts",
"**/*.shim.ts",
"src/main*.ts"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"angularCompilerOptions": {
"genDir": ".",
"entryModule": "src/app/app.module#AppModule"
}
}
将其更改为commonjs时效果很好。
我的量角器配置中是否需要添加任何内容来支持它?或者有没有办法可以定位一个单独的tsconfig文件?
谢谢!
编辑:我已经弄清楚如何定位单独的tsconfig文件,你可以通过ts-node require来做,并传递一些选项。 ts-node实际上就是打字稿,是一个努力弄清楚是什么让它神奇地变化的斗争。 require('ts-node').register({
lazy: true,
project: './config/tsconfig-commonjs.json'
});