首页 > 解决方案 > tsconfig ComplilerOptions 模块:“esnext”导致 SyntaxError:无法在模块外使用 import 语句

问题描述

我正在使用量角器设置 E2E 测试。因此,我的目标是我的 tsconfig 文件:

量角器.conf.js

...
onPrepare() {
    require('ts-node').register({
      project: require('path').join(__dirname, '../tsconfig.json')
    });
  }  
...

当我有这个配置时:

{
    "compilerOptions": {
        "module": "esnext",
        "target": "es2015",
...

然后我运行ng e2e我得到这个错误:

C:\git\training\Example.Web\ClientApp\e2e\src\steps\counter.steps.ts:10 从“@cucumber/cucumber”导入 { 之前,给定,然后,当 };^^^^^^

SyntaxError: 不能在模块外使用 import 语句

当我将 tsconfg 更改为:

{
    "compilerOptions": {
        "module": "CommonJs",
        "target": "es2015",
...

它工作得很好。我的问题是,“esnext”到底有什么问题?这就是 Visual Studio 模板添加的值。顾名思义,它是针对最新版本的,对吧?import最新版本肯定支持语法,不是吗?

标签: protractortsconfigangular-e2e

解决方案


推荐阅读