【问题标题】:No specs found Reshaper(2017.2.2) TypeScript(2.6.1) Jasmine(2.7.0) when using import {}使用 import {} 时未找到规范 Reshaper(2017.2.2) TypeScript(2.6.1) Jasmine(2.7.0)
【发布时间】:2018-04-30 08:57:15
【问题描述】:

设置:

  • Visual Studio 2017
  • 重塑者(2017.2.2)
  • TypeScript(2.6.1)
  • 茉莉花(2.7.0)

问题:

  • 浏览器显示网络测试启动器并显示消息“未找到规范”
  • 控制台错误可见:未捕获的 ReferenceError:exports 未在 referenceFile:2 中定义
  • 未捕获的 ReferenceError:未在 Tests.js:2 中定义导出

其他信息:

如果我在开发工具中点击referenceFile:2,我可以看到该文件的源JS代码,内容如下:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var User = (function () {
    function User(name, surname) {
        this._name = name;
        this._surname = surname;
    }
    Object.defineProperty(User.prototype, "Name", {
        get: function () {
            return this._name;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(User.prototype, "Surname", {
        get: function () {
            return this._surname;
        },
        enumerable: true,
        configurable: true
    });
    return User;
}());
exports.User = User;
//# sourceMappingURL=User.js.map

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "lib": ["es5"],
    "sourceMap": true
  },
  "exclude": [
    "node_modules"
  ]
}

package.json

{
  "name": "nodejs-console-app",
  "version": "0.0.0",
  "description": "NodejsConsoleApp",
  "main": "app.js",
  "author": {
    "name": "ms"
  },
  "devDependencies": {
    "@types/node": "^6.0.87",
    "jasmine": "^2.8.0"
  },
  "dependencies": {
    "@types/jasmine": "^2.8.2"
  }
}

知道如何解决这个问题吗?

更新: 该问题是由 tsconfig.json 中指定的 commonJs 模块类型引起的。 这是很多模板提出的默认值,也是我用得最多的一个。 不幸的是,CommonJS 不能立即在浏览器中执行,它需要被打包/浏览才能在浏览器中执行。 对于源代码,我使用 Gulp>browserify,一切正常。

我的期望是让 resharper 为我做肮脏的工作,但事实并非如此。 如何使用 resharper 运行这些测试而不会出现错误,在我的情况下,我什至不需要打开浏览器,因此它可以在节点中运行。

【问题讨论】:

    标签: typescript jasmine resharper


    【解决方案1】:

    TypeScript 模块编译确实很重要,我使用的是 CommonJS,但浏览器不支持,R# 对此没有做任何事情。

    在 tsconfig.json > compilerOptions > 模块中,可以指定以下选项之一:commonjs、amd、system、umd、es6。

    使用 R#,您可以而且应该使用 es6

    有关此的更多信息: Typescript Modules Typescript Module Resolution

    【讨论】:

      猜你喜欢
      • 2021-05-20
      • 2012-01-08
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 2014-09-30
      • 2020-04-13
      相关资源
      最近更新 更多