Vitest 无法使用 require() 导入到 CommonJS 模块中

问题描述 投票:0回答:1

我正在运行 vitest runner。然后我看到有人可能 vitest 正在从我的 .ts 文件生成一些 .js 文件:

我收到的错误消息似乎源自 uiElementsCreator.test.js:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var vitest_1 = require("vitest");
/*import { CompositeChangeResponse, ChangeResponseTreeItem, ConfigurationResult } from "../src/App/apis/models/compositeChangeResponse";
import { GlobalStore } from '../src/App/components/ConfigurationStepper/_shared/helper/globalStore';*/
(0, vitest_1.describe)("Test UiElementsCreator", function () {
    (0, vitest_1.describe)("test request composite on value change", function () {
        (0, vitest_1.test)("Given element is mandatory and active with specific id, expect them 

...为了清晰起见,删除了其余测试

错误:

 FAIL  test/lib/test/uiElementsCreator.test.js [ test/lib/test/uiElementsCreator.test.js ]
Error: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead.

If you are using "import" in your source code, then it's possible it was bundled into require() automatically by your bundler. In that case, do not bundle CommonJS output since it will never work with Vitest, or use dynamic impo
rt() which is available in all CommonJS modules.

vitest 似乎正在使用 require(),尽管它确实抱怨它!

   var vitest_1 = require("vitest");

我这里做错了什么?

require es6-modules vitest
1个回答
0
投票

是时候将您的项目从 CommonJS 升级到 ES6 了。

© www.soinside.com 2019 - 2024. All rights reserved.