【发布时间】:2023-03-23 14:56:02
【问题描述】:
Typescript 未编译外部类 - 量角器测试。
我正在尝试将我作为 npm 包发布的外部 typescript 类用于我的量角器测试,该测试也在 typescript 中。我用 gulp 编译打字稿。当我在与测试相同的项目中拥有该类时,一切工作正常,但是现在我尝试通过 node_modules 作为包使用它,但出现错误。
在运行时,我得到Unexpected token error。
看起来打字稿没有编译。是打字错误吗?我需要为我的包生成类型吗?
import { Helper } from './src/helper';
^
SyntaxError: Unexpected token {
打包文件系统
e2e/src/helper
index.ts
package.json
tsconfig.json
index.ts
import { Helper } from './src/helper';
export { Helper };
package.json
"name": "my-project",
"main": "index.ts",
"types": "index.d.ts",
"version": "0.0.1",
tsconfig.json
{
"compilerOptions": {
"outDir": "lib",
"rootDir": ".",
"target": "es5",
"module": "commonjs",
"declaration": true,
"types": [
]
}
}
测试
Protractor 测试文件,我在其中尝试使用外部类,已导入node_modules
test.ts
import { Helper } from 'my-project';
describe(' Test Description' , () => {
let helper: Helper;
before(async () => {
helper = new Helper();
});
running this test gives me error - SyntaxError: Unexpected token {
【问题讨论】:
标签: typescript protractor typescript-typings