koa-shopify-auth
koa-shopify-auth copied to clipboard
Node ESM support: The requested module '@shopify/koa-shopify-auth' does not provide an export named 'verifyRequest'
Overview
I am trying to import the library to node with experimental modules enabled (node --expermental-modules server.js
, but the ESM loader claims that the export doesn't exist.
I have tried various other ways of importing like {* as shopifyAuth}
but those don't seem to work either. I think that the reason for this is issue is defined in https://nodejs.org/api/esm.html#esm_writing_dual_packages_while_avoiding_or_minimizing_hazards
Building a wrapper like the one mentioned in the repo should solve the problem:
// ./node_modules/pkg/wrapper.mjs
import cjsModule from './index.cjs';
export const name = cjsModule.name;
This approach is appropriate for any of the following use cases:
The package is currently written in CommonJS and the author would prefer not to refactor it into ES module syntax, but wishes to provide named exports for ES module consumers.
Motivation
Better support for @shopify/koa-shopify-auth and ESM modules support.
Code
TypeScript Version: 3.8.3 Node version: 14.0.0
import createShopifyAuth, { verifyRequest } from '@shopify/koa-shopify-auth';
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": false,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"outDir": "build"
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"server.ts"
]
}
command:
"start": "tsc && node --experimental-modules ./build/server.js"
Expected behavior:
Everything works
Actual behavior:
The requested module '@shopify/koa-shopify-auth' does not provide an export named 'verifyRequest'
We would like to eventually support esm modules in the packages in this repo, but it's not currently high in our priorities and would require significant effort to do on the scale of all ~70 packages.
If you feel up to opening a PR I will be happy to review it.
That’s awesome and totally understandable! I’ll try to find time to create a PR or at least a poc!
@petetnt fyi we will likely be fixing this by adopting a diff build tool for the repo sometime soon (see https://github.com/Shopify/quilt/issues/1522 for updates)
Sounds neat!
Note that this repo is no longer maintained and this issue will not be reviewed. Prefer the official JavaScript API library. If you still want to use Koa, see simple-koa-shopify-auth for a potential community solution.