Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 摩卡:找不到模块_Javascript_Node.js_Mocha.js - Fatal编程技术网

Javascript 摩卡:找不到模块

Javascript 摩卡:找不到模块,javascript,node.js,mocha.js,Javascript,Node.js,Mocha.js,应用程序结构如下所示: index.js -src --分贝 ---index.js ---model.js -试验 --test.js 在我的index.js中,我必须像这样导入数据库 const db=require('./src/db') 使用npm运行时,应用程序运行良好 但是,当我尝试使用mocha运行测试时,它会给我错误 错误:找不到模块'./src/db' 我的test.js文件如下: //开发依赖性 const chai=require(‘chai’) const

应用程序结构如下所示:

index.js
-src
--分贝
---index.js
---model.js
-试验
--test.js
在我的index.js中,我必须像这样导入数据库

const db=require('./src/db')
使用
npm运行时,应用程序运行良好
但是,当我尝试使用mocha运行测试时,它会给我错误

错误:找不到模块'./src/db'
我的test.js文件如下:

//开发依赖性
const chai=require(‘chai’)
const chaiHttp=require('chai-http')
const should=chai.should()
const app=require('./索引')

chai.use(chaiHttp)
不应该是
const-app=require(“../index”)
?正如@JohannesMerz上面的评论,您的相对链接不正确。