Open sajjadalis opened 4 years ago
Can you please share your package.json
and how you are importing the package?
@arifulhb Thanks for the reply and sorry for a bit late response.
Here is my package.json
.
{
"name": "earbudshop",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"amazon-pa-api50": "0.0.3",
"axios": "^0.19.2",
"cookieparser": "^0.1.0",
"core-js": "^3.4.4",
"js-cookie": "^2.2.1",
"strapi-sdk-javascript": "^0.3.3",
"vue": "^2.6.10",
"vue-router": "^3.1.3",
"vuex": "^3.1.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.0",
"@vue/cli-plugin-router": "^4.1.0",
"@vue/cli-plugin-vuex": "^4.1.0",
"@vue/cli-service": "^4.1.0",
"@vue/eslint-config-prettier": "^5.0.0",
"vue-template-compiler": "^2.6.10"
}
}
I created a separate file for configuration
amazon.js
const Api = require('amazon-pa-api50')
const Config = require('amazon-pa-api50/lib/config')
// By Default all resources and will connect to United States
let myConfig = new Config();
/**
* Add your Credentials Here
*/
myConfig.accessKey = 'APIKEY'
myConfig.secretKey = 'APISECRET'
myConfig.partnerTag = 'partnetag'
const api = new Api(myConfig)
export default api;
Here is my code inside AddProducts.vue
component.
<template>
<div class="add-products">
<button @click="getProducts" class="uk-button">Get Products</button>
</div>
</template>
<script>
import api from '@/init/amazon.js'
export default {
methods: {
getProducts() {
api.getItemById(['B079JD7F7G']).then((response) => {
console.log(' ===== find by Item ids =====')
console.log('data', response.data)
}).catch((error) => {
console.log('Error: ', error)
})
}
}
}
</script>
When i run npm run serve
. I get that above error during build process. I tried to import amazon-pa-api50
directly inside AddProducts.vue file but it gets the same error during build process.
If i include api.getItemById()
inside amazon.js
and run node amazon.js
then i get response perfectly fine. As mentioned above, i had same issue with official sdk when i include it in .vue file. Any help what i'm doing wrong.
Thanks again.
@arifulhb any help on this? What am i doing wrong?
Thanks for your time.
@sajjadalis Could you resolve the issue? I'm having a very similar problem.
I will also have a look this weekend.
First of all, thanks for providing this easy solution. Official SDK config is a mess.
I have been trying official sdk earlier with my VueJS application and during compile in serve mode, i was getting dependencies were not found error. So i just tried
amazon-pa-api50
but i have the same issue during compile process.It works fine if i try to
node amazon.js
in console and i'm getting proper response (same for official sdk)But when i including it inside .vue file then it won't work.
Also VSCode is showing this message on require. http://prntscr.com/qt023x
Any suggestion?
Thanks