Issue summary
Hi shopify-node-api team,
Thanks for making this node API.
I am trying to build an embedded app with Vue/Koa.js, I just start by following the tutorial of @shopify/koa-shopify-auth. However, when I tried to run the example app via command node server.js
,
it return an error said:
Shopify.Context.initialize({
^
TypeError: Cannot read property 'initialize' of undefined
It confused me, so I came here following the getting start tutorial of @shopify/shopify-node-api, and carefully checked every input arguments(API_KEY, API_SECRET_KEY, SCOPES, HOST, all these value are correct).
Unfortunately, I got just the same error.
Expected behavior
I expected the example app can successfully executed, or at least the function Shopify.Context.initialize
could work.
Actual behavior
when I tried to run the example app via command node server.js
,
it return an error said:
Shopify.Context.initialize({
^
TypeError: Cannot read property 'initialize' of undefined
Even I checked the tutorial at here, it still end with same the error.
Steps to reproduce the problem
- Setup the files
- type
node server.js
Reduced test case
Following is my code(sever.js and package.json):
server.js
import 'isomorphic-fetch';
import dotenv from 'dotenv';
import Koa from 'koa';
import session from 'koa-session';
import shopifyAuth, {default as verifyRequest} from '@shopify/koa-shopify-auth';
import Shopify, {ApiVersion} from '@shopify/shopify-api';
dotenv.config();
const port = parseInt(process.env.port, 10) || 3000;
const {SHOPIFY_API_SECRET, SHOPIFY_API_KEY} = process.env;
//initialize the library
Shopify.Context.initialize({
API_KEY: SHOPIFY_API_KEY,
API_SECRET_KEY: SHOPIFY_API_SECRET,
SCOPES: [process.env.SHOPIFY_APP_SCOPES],
HOST_NAME: process.env.SHOPIFY_APP_URL.replace(/^https:\/\//, ''),
IS_EMBEDDED_APP: true,
API_VERSION: ApiVersion.October20,
SESSION_STORAGE: new Shopify.Session.MemorySessionStorage()
});
const server = new Koa();
server.keys = [SHOPIFY_API_SECRET];
server.use(session(server))
.use(
shopifyAuth({
afterAuth(ctx){
const {shop, accessToken} = ctx.session;
console.log('First Trial Success!', accessToken);
ctx.redirect('/');
},
}),
)
.use(verifyRequest())
.use(ctx => {
ctx.body = '๐';
});
server.listen(port, ()=>{
console.log('> Ready on http://localhost:${port}');
});
package.json
{
"name": "koala",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Dan Hsu",
"license": "ISC",
"dependencies": {
"@shopify/app-bridge-utils": "^1.29.0",
"@shopify/koa-shopify-auth": "^4.0.2",
"@shopify/shopify-api": "^1.1.0",
"@types/koa": "^2.13.1",
"dotenv": "^8.2.0",
"isomorphic-fetch": "^3.0.0",
"koa": "^2.13.1",
"koa-router": "^8.0.8",
"koa-session": "^6.1.0"
}
}
Checklist