Skip to content

Commit

Permalink
getPluginByName fails unexpectedly when plugin is not prefixed with @… (
Browse files Browse the repository at this point in the history
#8097)

* getPluginByName fails unexpectedly when plugin is not prefixed with @graphql-codgen/

We've been finding that our error code thrown is not `MODULE_NOT_FOUND` but rather `ERR_MODULE_NOT_FOUND` leading to codegen cli throwing and failing plugin load when trying the first plugin option. Since the error returned isn't `MODULE_NOT_FOUND`. As small double check here by adding the || `ERR_MODULE_NOT_FOUND` should account for that case. 

IMO this is a small but pretty urgent fix as it could be incorrectly throwing in some environments. I don't personally know the cause for the different error code, but our repo is via Vite / Node 17 and is ESM based.

* Oopsie, need &&

* Create green-dogs-wait.md
  • Loading branch information
stolinski committed Jul 15, 2022
1 parent c52709b commit 32c1560
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .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.
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/src/plugins.ts
Expand Up @@ -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}`,
`
Expand Down

1 comment on commit 32c1560

@vercel
Copy link

@vercel vercel bot commented on 32c1560 Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.