diff --git a/.changeset/green-dogs-wait.md b/.changeset/green-dogs-wait.md new file mode 100644 index 00000000000..1703fd1a292 --- /dev/null +++ b/.changeset/green-dogs-wait.md @@ -0,0 +1,8 @@ +--- +"@graphql-codegen/cli": patch +--- + +getPluginByName fails unexpectedly when plugin is not prefixed with @graphq-codegen in ESM context + +MODULE_NOT_FOUND is the error code you receive in a CommonJS context when you require() a module and it does not exist. +ERR_MODULE_NOT_FOUND is the error code you receive in an ESM context when you import or import() ad module that does not exist. diff --git a/packages/graphql-codegen-cli/src/plugins.ts b/packages/graphql-codegen-cli/src/plugins.ts index 1c846911b2a..6bf8aaf8912 100644 --- a/packages/graphql-codegen-cli/src/plugins.ts +++ b/packages/graphql-codegen-cli/src/plugins.ts @@ -22,7 +22,7 @@ export async function getPluginByName( try { return await pluginLoader(moduleName); } catch (err) { - if (err.code !== 'MODULE_NOT_FOUND') { + if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') { throw new DetailedError( `Unable to load template plugin matching ${name}`, `