Closed davesaloria closed 2 years ago
I experienced the same problem following the Build a Shopify App with Node and React tutorial in Step 3. Resolved it by:
node_modules
folder and .package-lock.json
npm install
Also having this issue
I experienced the same problem following the Build a Shopify App with Node and React tutorial in Step 3. Resolved it by:
- Switching to the root folder in the CLI
- Deleting the
node_modules
folder and.package-lock.json
- Re-running
npm install
This did not resolve. Should I add a var to the .env?
Hey everyone! That error could be due to a number of different reasons, but if you just checked out this repo and ran it, it is possible that you're missing a .env
file, which will need the following values:
SHOPIFY_API_KEY=<key>
SHOPIFY_API_SECRET=<secret key>
SCOPES=<the scopes your app needs>
HOST=<your app's ngrok address>
If this isn't the issue you're facing, can you please share the code from server.js
around the error, so we can see if it is a bug in the app?
Hope this helps!
I had this same problem but realized that I didn't have a .env
file like @paulomarg said.. mine wasprocess.env
but instead needs to just be .env
.. then my script ran. :)
Im having this issue as well. I wil attach my server.js file. My process.env is a .env file, made it with vs code
`require('isomorphic-fetch'); const dotenv = require('dotenv'); const Koa = require('koa'); const next = require('next'); const {default: createShopifyAuth} = require('@shopify/koa-shopify-auth'); const {verifyRequest} = require('@shopify/koa-shopify-auth'); const {default: Shopify, ApiVersion} = require('@shopify/shopify-api'); const Router = require('koa-router');
dotenv.config();
Shopify.Context.initialize({ API_KEY: process.env.SHOPIFY_API_KEY, API_SECRET_KEY: process.env.SHOPIFY_API_SECRET, SCOPES: process.env.SHOPIFY_API_SCOPES.split(","), HOST_NAME: process.env.SHOPIFY_APP_URL.replace(/https:\/\//, ""), API_VERSION: ApiVersion.October20, IS_EMBEDDED_APP: true, SESSION_STORAGE: new Shopify.Session.MemorySessionStorage(), });
const port = parseInt(process.env.PORT, 10) || 3000; const dev = process.env.NODE_ENV !== 'production'; const app = next({dev: dev}); const handle = app.getRequestHandler();
const ACTIVE_SHOPIFY_SHOPS = {};
app.prepare().then(() => { const server = new Koa(); const router = new Router(); server.keys = [Shopify.Context.API_SECRET_KEY];
server.use( createShopifyAuth({ afterAuth(ctx) { const {shop, scope} = ctx.state.shopify; ACTIVE_SHOPIFY_SHOPS[shop] = scope;
ctx.redirect(`/?shop=${shop}`);
},
}),
);
const handleRequest = async (ctx) => { await handle(ctx.req, ctx.res); ctx.respond = false; ctx.res.statusCode = 200; };
router.get("/", async (ctx) => { const shop = ctx.query.shop;
if (ACTIVE_SHOPIFY_SHOPS[shop] === undefined) {
ctx.redirect(`/auth?shop=${shop}`);
} else {
await handleRequest(ctx);
}
});
router.get("(/_next/static/.)", handleRequest); router.get("/_next/webpack-hmr", handleRequest); router.get("(.)", verifyRequest(), handleRequest);
server.use(router.allowedMethods()); server.use(router.routes());
server.listen(port, () => {
console.log(> Ready on http://localhost:${port}
);
});
});`
I had this same issue and the problem was that in a secret I had in the .env file the value contained $ when I removed this character it worked
Issue summary
when I do npm run dev at terminal it returns a TypeError :
TypeError: Cannot read property 'split' of undefined at Object. (C:\Users\daves\Project\sample-app\server.js:15:42)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47