Shopify / shopify-api-js

Shopify Admin API Library for Node. Accelerate development with support for authentication, graphql proxy, webhooks
MIT License
942 stars 390 forks source link

Error: Missing adapter implementation for 'abstractRuntimeString' #764

Closed FlorianB385 closed 1 year ago

FlorianB385 commented 1 year ago

Hi! We would like to build an simple Shopify App in nuxt3. After installation and configuration, we call the shopifyApi function. Then the error occurs. Some issue report says, that we import first "@shopify/shopify-api/adapters/node" but that didn't help either.

[nitro] [dev] [uncaughtException] Error: Missing adapter implementation for 'abstractRuntimeString' - make sure to import the appropriate adapter for your platform
    at abstractRuntimeString (/Users/florianbottmann/Documents/workspace/shopify-donation/node_modules/@shopify/shopify-api/runtime/platform/runtime-string.js:6:11)
    at shopifyApi (/Users/florianbottmann/Documents/workspace/shopify-donation/node_modules/@shopify/shopify-api/lib/index.js:50:117)
    at file:///Users/florianbottmann/Documents/workspace/shopify-donation/.nuxt/dev/index.mjs:676:1
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
paper-krane commented 1 year ago

Having this exact issue as well. Been scouring the Shopify docs to see if I missed anything to no avail.

vtrikoupis commented 1 year ago

Also encountered this. I assume this has to do with not importing the relevant node adapters

import '@shopify/shopify-api/adapters/node'

Can anyone confirm?

mkevinosullivan commented 1 year ago

Yes, that error is an indication that the adapter hasn't been loaded before the first call to shopifyApi (https://github.com/Shopify/shopify-api-js/blob/main/docs/migrating-to-v6.md#migrating-to-v6).

import '@shopify/shopify-api/adapters/node';
import { ... } from '@shopify/shopify-api';
jamalsoueidan commented 1 year ago

StorefrontClient: Using a private storefront token is recommended for server environments. Refer to the authentication https://shopify.dev/api/storefront#authentication documentation for more details. ReferenceError: process is not defined at nodeRuntimeString (/Users/jamalsoueidan/Development/storefront/node_modules/@shopify/shopify-api/adapters/node/adapter.ts:92:18) Remix.

codeustad commented 1 year ago

Still getting this error with @shopify/shopify-api": "7.5.1

ReferenceError: process is not defined
    at nodeRuntimeString (.../node_modules/@shopify/shopify-api/adapters/node/adapter.ts:92:18)
    at shopifyApi2 (.../node_modules/@shopify/shopify-api/lib/index.ts:77:62)
    at Object.fetch (.../server.ts:70:23)
    at ServiceWorkerGlobalScope.[kDispatchFetch] (.../node_modules/@miniflare/core/src/standards/event.ts:385:13)
    at /.../node_modules/@shopify/mini-oxygen/dist/mini-oxygen/server.js:146:24
BYohann commented 11 months ago

I want to confirm that it will work if you import the library as with an await inside a nitro plugin

export default defineNitroPlugin(async (nitroApp) => { await import('@shopify/shopify-api/adapters/node') })

This way, the adapter is registered and work for Nuxt server functions with Nitro

skoulix commented 7 months ago

I want to confirm that it will work if you import the library as with an await inside a nitro plugin

export default defineNitroPlugin(async (nitroApp) => { await import('@shopify/shopify-api/adapters/node') })

This way, the adapter is registered and work for Nuxt server functions with Nitro

@BYohann

I'm doing it the exact same way in a Nitro plugin and still getting the same error => "Error: Missing adapter implementation for 'abstractRuntimeString'"

Is this way what you are currently using?

Thanks.

abpoloclub commented 7 months ago

I want to confirm that it will work if you import the library as with an await inside a nitro plugin export default defineNitroPlugin(async (nitroApp) => { await import('@shopify/shopify-api/adapters/node') }) This way, the adapter is registered and work for Nuxt server functions with Nitro

@BYohann

I'm doing it the exact same way in a Nitro plugin and still getting the same error => "Error: Missing adapter implementation for 'abstractRuntimeString'"

Is this way what you are currently using?

Thanks.

Create a middleware server like server/middleware/shopifyAdapters.js with:

export default defineEventHandler((event) => {
import("@shopify/shopify-api/adapters/node");
});

This worked for me

skoulix commented 7 months ago

I want to confirm that it will work if you import the library as with an await inside a nitro plugin export default defineNitroPlugin(async (nitroApp) => { await import('@shopify/shopify-api/adapters/node') }) This way, the adapter is registered and work for Nuxt server functions with Nitro

@BYohann I'm doing it the exact same way in a Nitro plugin and still getting the same error => "Error: Missing adapter implementation for 'abstractRuntimeString'" Is this way what you are currently using? Thanks.

Create a middleware server like server/middleware/shopifyAdapters.js with:

export default defineEventHandler((event) => {
import("@shopify/shopify-api/adapters/node");
});

This worked for me

Thank you!