本文介绍了依赖周期检测到导入/无周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在ES6中设置API端点.在我的主服务器文件中,我尝试导入路由器模块,但收到错误检测到依赖周期的导入/无周期".请在下面找到我的代码,以获取批准和帮助.
I am trying to set up API endpoints in ES6. In my main server file, I tried to import the router module but I get the error "dependency cycle detected import/no-cycle". Please find my code below for clearance and assistance.
import express from 'express';
import bodyParser from 'body-parser';
import router from './routes/routes';
const app = express();
const PORT = process.env.PORT || 8080;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// app.use(routes);
app.use('/api/v1', router);
const run = () => console.log('way to go server!');
app.listen(PORT, run);
export default app;
推荐答案
这可能是直接参考(A-> B-> A)
的问题,甚至您可能正在这样做.
This could be a direct reference (A -> B -> A)
issue, which even you might be doing.
// file a.ts
import { b } from 'b';
...
export a;
// file b.ts
import { a } from 'a';
...
export b;
详细阅读"此处有关从您的JavaScript项目":
Read HERE more about "Eliminate Circular Dependencies from Your JavaScript Project":
一旦我在 vue.js 项目中遇到了问题,出现问题的代码就是这样:
Once I had the issue in vue.js project and the code that had issue was something like this:
<script>
import router from '@/router';
import { requestSignOut } from '../../api/api';
export default {
name: 'sign-out',
mounted() {
requestSignOut().then((data) => {
if (data.status === 'ok') {
router.push({ name: 'sign-in' });
}
});
},
};
</script>
然后我以这种方式修复它:
Then I fixed it this way:
<script>
import { requestSignOut } from '@/api/api';
export default {
name: 'sign-out',
mounted() {
requestSignOut().then((data) => {
if (data.status === 'ok') {
this.$router.push({ name: 'sign-in' });
}
});
},
};
</script>
这篇关于依赖周期检测到导入/无周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!