Skip to content

Commit 32c1560

Browse files
authored
getPluginByName fails unexpectedly when plugin is not prefixed with @… (dotansimha#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
1 parent c52709b commit 32c1560

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.changeset/green-dogs-wait.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@graphql-codegen/cli": patch
3+
---
4+
5+
getPluginByName fails unexpectedly when plugin is not prefixed with @graphq-codegen in ESM context
6+
7+
MODULE_NOT_FOUND is the error code you receive in a CommonJS context when you require() a module and it does not exist.
8+
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.

packages/graphql-codegen-cli/src/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function getPluginByName(
2222
try {
2323
return await pluginLoader(moduleName);
2424
} catch (err) {
25-
if (err.code !== 'MODULE_NOT_FOUND') {
25+
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
2626
throw new DetailedError(
2727
`Unable to load template plugin matching ${name}`,
2828
`

0 commit comments

Comments
 (0)