只是从Shopify开始,并试图获得订单。根据Shopify API文档,下面是我的代码:
const Shopify = require('@shopify/shopify-api');
const client = new Shopify.Clients.Rest('my-store.myshopify.com',
process.env.SHOPIFY_KEY);
module.exports.getShopifyOrderById = async (orderId) => {
return await client.get({
path: `orders/${orderId}`,
});
}当我执行这段代码时,我得到了以下错误:
TypeError: Cannot read properties of undefined (reading 'Rest')
似乎找不到问题出在哪里。
发布于 2021-11-11 09:35:21
您需要使用对象析构来获取Shopify对象,或者使用默认导出,如下所示。
const { Shopify } = require('@shopify/shopify-api');
const client = new Shopify.Clients.Rest('my-store.myshopify.com',
process.env.SHOPIFY_KEY);或
const Shopify = require('@shopify/shopify-api').default;
const client = new Shopify.Clients.Rest('my-store.myshopify.com',
process.env.SHOPIFY_KEY);或
const ShopifyLib = require('@shopify/shopify-api');
const client = new ShopifyLib.Shopify.Clients.Rest('my-store.myshopify.com',
process.env.SHOPIFY_KEY);这与如何在CommonJS中模拟ES6模块以及如何导入模块有关。你可以使用read about that here。
https://stackoverflow.com/questions/69920772
复制相似问题