gpt4 book ai didi

node.js - 我收到错误,无法使用 mocha 找到模块 './--require.js'

转载 作者:太空宇宙 更新时间:2023-11-04 02:44:58 25 4
gpt4 key购买 nike

我正在尝试使用 mocha 和 chai 编写单元测试用例,但运行测试用例时出现错误:-Cannot find module './--require.js

脚本是:- "test": "mocha --require babel-core/register 'server/api/**/*.test.js'"

完整错误:-

D:\gitlab-to-azure\blik-app\node_modules\yargs\yargs.js:1163
else throw err
^

Error: Cannot find module './--require.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.getConstants (D:/gitlab-to-azure/blik-app/server/config/environment/index.js:12:16)
at Object.<anonymous> (D:/gitlab-to-azure/blik-app/server/app.js:20:25)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at loader (D:\gitlab-to-azure\blik-app\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (D:\gitlab-to-azure\blik-app\node_modules\babel-register\lib\node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (D:/gitlab-to-azure/blik-app/server/api/group/group.test.js:2:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at loader (D:\gitlab-to-azure\blik-app\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (D:\gitlab-to-azure\blik-app\node_modules\babel-register\lib\node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at D:\gitlab-to-azure\blik-app\node_modules\mocha\lib\mocha.js:334:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (D:\gitlab-to-azure\blik-app\node_modules\mocha\lib\mocha.js:331:14)
at Mocha.run (D:\gitlab-to-azure\blik-app\node_modules\mocha\lib\mocha.js:809:10)
at Object.exports.singleRun (D:\gitlab-to-azure\blik-app\node_modules\mocha\lib\cli\run-helpers.js:108:16)
at exports.runMocha (D:\gitlab-to-azure\blik-app\node_modules\mocha\lib\cli\run-helpers.js:142:13)
at Object.exports.handler.argv [as handler] (D:\gitlab-to-azure\blik-app\node_modules\mocha\lib\cli\run.js:292:3)
at Object.runCommand (D:\gitlab-to-azure\blik-app\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (D:\gitlab-to-azure\blik-app\node_modules\yargs\yargs.js:1087:28)
at Object.parse (D:\gitlab-to-azure\blik-app\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (D:\gitlab-to-azure\blik-app\node_modules\mocha\lib\cli\cli.js:68:6)
at Object.<anonymous> (D:\gitlab-to-azure\blik-app\node_modules\mocha\bin\mocha:164:29)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)```


Folder Structure:-
server
api
groups
controller.js
model.js
groups.test.js

最佳答案

您需要获得 Mocha 运行者的完整路径资格,您可以尝试这样的事情

"test": "./node_modules/.bin/mocha --compilers js:@babel/register 'server/api/**/*.test.js'"

关于node.js - 我收到错误,无法使用 mocha 找到模块 './--require.js',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58992171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com