Trouble getting Admin API working in Hydrogen Shopify build

In server.js I have this code:

import '@shopify/shopify-app-remix/server/adapters/node';
import {
  LATEST_API_VERSION,
  shopifyApp,
} from '@shopify/shopify-app-remix/server';

if (!process.env.SHOPIFY_API_KEY || !process.env.SHOPIFY_API_SECRET || !process.env.SHOPIFY_APP_URL) {
  throw new Error('Environment variables not defined');
}

export const shopifyTEST = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY,
  apiSecretKey: process.env.SHOPIFY_API_SECRET,
  appUrl: process.env.SHOPIFY_APP_URL,
  scopes: ['read_analytics'],
  apiVersion: LATEST_API_VERSION,
});

shopify-app-remix is installed via npm, but running the code npm run dev I see the following errors about crypto

X [ERROR] Could not resolve "crypto"

    node_modules/@shopify/shopify-app-remix/build/cjs/server/adapters/node/index.js:3:21:
      3 │ var crypto = require('crypto');
        ╵                      ~~~~~~~~

  The package "crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

I didn’t want to execute platform 'node' unless I was certain this is the direction I wanted go. Any ideas?

Thanks

Hi @rattlesnakeMT ,There is a solution here that I think you can try: https://community.shopify.com/c/shopify-apps/the-package-quot-crypto-quot-wasn-t-found-on-the-file-system-but/m-p/2336855/highlight/true#M71370

However please note that Hydrogen is now built with a Worker environment, not Node.js so you should not use any library that uses some Node method like “fs”…
If you just want to use Admin API for your Hydrogen store, it is better to create a custom app, obtain the token, and use it directly.

Great. That was the direction I was hoping to get on this. Curious if you can point me in the right direction in regards to accessing custom apps in the Hydrogen environment? I’m assuming you would install it via the admin, but how would you access it on the frontend? Thanks for the help!!

Hi @rattlesnakeMT , The Custom app is the app that you can install on one specific store only via the Shop Admin, after you create custom app and install it, you can obtain the token directly. Please follow this guide to do it: https://help.shopify.com/en/manual/apps/app-types/custom-apps#create-and-install-a-custom-app