admin管理员组文章数量:1025269
I created a module in which I keep functions to call an api. While 'requiring' it, I get the following error:
./src/Components/Search/SearchPage.js
Module not found: Can't resolve '../utils/api' in 'C:\Users\riksch\Dropbox\projects\Current\greenmp\frontend\src\Components\Search'
My main question is: how do I correctly import the api module into SearchPage.js?
Here is the structure of my project:
I've highlighted the files that I use, 1 is the file that I import (require) from, and 2 is the module I try to import.
This worked before, but now that I changed the folder structure, even after adjusting the path, I can't get it too work.
I've tried different import paths, all with the same error.
SearchPage.js require statement
const api = require('../utils/api')
api.js
var axios = require('axios')
module.exports = {
retrievePlants: function(search_query, locale) {
console.log("api.retrievePlants executes")
console.log("url: " + 'http://127.0.0.1:8000/search/'+locale+'/'+search_query)
//FIXME: hardcoded URL HOST
// return axios.get('https://127.0.0.1/search/'+locale+'/'+search_query)
return axios.get('http://127.0.0.1:8000/search/'+locale+'/'+search_query)
.then(function(response) {
console.log("response.data:")
console.log(response.data)
return response.data
})
.catch(function(error) {
console.log("Error in Components.utils.api.retrievePlants:")
console.log(error)
console.log("console.log(error.response.data):")
console.log(error.response.data)
})
},
}
I created a module in which I keep functions to call an api. While 'requiring' it, I get the following error:
./src/Components/Search/SearchPage.js
Module not found: Can't resolve '../utils/api' in 'C:\Users\riksch\Dropbox\projects\Current\greenmp\frontend\src\Components\Search'
My main question is: how do I correctly import the api module into SearchPage.js?
Here is the structure of my project:
I've highlighted the files that I use, 1 is the file that I import (require) from, and 2 is the module I try to import.
This worked before, but now that I changed the folder structure, even after adjusting the path, I can't get it too work.
I've tried different import paths, all with the same error.
SearchPage.js require statement
const api = require('../utils/api')
api.js
var axios = require('axios')
module.exports = {
retrievePlants: function(search_query, locale) {
console.log("api.retrievePlants executes")
console.log("url: " + 'http://127.0.0.1:8000/search/'+locale+'/'+search_query)
//FIXME: hardcoded URL HOST
// return axios.get('https://127.0.0.1/search/'+locale+'/'+search_query)
return axios.get('http://127.0.0.1:8000/search/'+locale+'/'+search_query)
.then(function(response) {
console.log("response.data:")
console.log(response.data)
return response.data
})
.catch(function(error) {
console.log("Error in Components.utils.api.retrievePlants:")
console.log(error)
console.log("console.log(error.response.data):")
console.log(error.response.data)
})
},
}
Share
Improve this question
asked May 31, 2018 at 10:23
Rik SchoonbeekRik Schoonbeek
4,5204 gold badges29 silver badges47 bronze badges
1
-
2
You need go up two directories.
../
(Out of search dir) and'../
(Out of Components) – Siya Mzam Commented May 31, 2018 at 10:25
1 Answer
Reset to default 6You have to go two directories up like below
const api = require('../../utils/api');
it will work.
I created a module in which I keep functions to call an api. While 'requiring' it, I get the following error:
./src/Components/Search/SearchPage.js
Module not found: Can't resolve '../utils/api' in 'C:\Users\riksch\Dropbox\projects\Current\greenmp\frontend\src\Components\Search'
My main question is: how do I correctly import the api module into SearchPage.js?
Here is the structure of my project:
I've highlighted the files that I use, 1 is the file that I import (require) from, and 2 is the module I try to import.
This worked before, but now that I changed the folder structure, even after adjusting the path, I can't get it too work.
I've tried different import paths, all with the same error.
SearchPage.js require statement
const api = require('../utils/api')
api.js
var axios = require('axios')
module.exports = {
retrievePlants: function(search_query, locale) {
console.log("api.retrievePlants executes")
console.log("url: " + 'http://127.0.0.1:8000/search/'+locale+'/'+search_query)
//FIXME: hardcoded URL HOST
// return axios.get('https://127.0.0.1/search/'+locale+'/'+search_query)
return axios.get('http://127.0.0.1:8000/search/'+locale+'/'+search_query)
.then(function(response) {
console.log("response.data:")
console.log(response.data)
return response.data
})
.catch(function(error) {
console.log("Error in Components.utils.api.retrievePlants:")
console.log(error)
console.log("console.log(error.response.data):")
console.log(error.response.data)
})
},
}
I created a module in which I keep functions to call an api. While 'requiring' it, I get the following error:
./src/Components/Search/SearchPage.js
Module not found: Can't resolve '../utils/api' in 'C:\Users\riksch\Dropbox\projects\Current\greenmp\frontend\src\Components\Search'
My main question is: how do I correctly import the api module into SearchPage.js?
Here is the structure of my project:
I've highlighted the files that I use, 1 is the file that I import (require) from, and 2 is the module I try to import.
This worked before, but now that I changed the folder structure, even after adjusting the path, I can't get it too work.
I've tried different import paths, all with the same error.
SearchPage.js require statement
const api = require('../utils/api')
api.js
var axios = require('axios')
module.exports = {
retrievePlants: function(search_query, locale) {
console.log("api.retrievePlants executes")
console.log("url: " + 'http://127.0.0.1:8000/search/'+locale+'/'+search_query)
//FIXME: hardcoded URL HOST
// return axios.get('https://127.0.0.1/search/'+locale+'/'+search_query)
return axios.get('http://127.0.0.1:8000/search/'+locale+'/'+search_query)
.then(function(response) {
console.log("response.data:")
console.log(response.data)
return response.data
})
.catch(function(error) {
console.log("Error in Components.utils.api.retrievePlants:")
console.log(error)
console.log("console.log(error.response.data):")
console.log(error.response.data)
})
},
}
Share
Improve this question
asked May 31, 2018 at 10:23
Rik SchoonbeekRik Schoonbeek
4,5204 gold badges29 silver badges47 bronze badges
1
-
2
You need go up two directories.
../
(Out of search dir) and'../
(Out of Components) – Siya Mzam Commented May 31, 2018 at 10:25
1 Answer
Reset to default 6You have to go two directories up like below
const api = require('../../utils/api');
it will work.
本文标签: javascriptReact Module not found Can39t resolve 39utilsapi39Stack Overflow
版权声明:本文标题:javascript - React Module not found: Can't resolve '..utilsapi' - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745620794a2159558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论