Skip to content

fix: use createRequire for node_modules resolution in VSCode extension#1171

Merged
aswamy merged 3 commits intoShopify:mainfrom
andershagbard:fix/vscode-node-modules-resolution
Apr 17, 2026
Merged

fix: use createRequire for node_modules resolution in VSCode extension#1171
aswamy merged 3 commits intoShopify:mainfrom
andershagbard:fix/vscode-node-modules-resolution

Conversation

@andershagbard
Copy link
Copy Markdown
Contributor

@andershagbard andershagbard commented Apr 9, 2026

Summary

  • Fixes the VSCode extension failing to resolve custom theme check packages (e.g. @grafikr/theme-check-extension/recommended.yml) from node_modules, while the CLI works fine.
  • The root cause: the extension's language server is bundled by webpack, which replaces require with its own module system. webpack's require.resolve ignores the paths option and returns a numeric module ID instead of a real file path.
  • The fix uses createRequire from node:module to create a proper Node.js require function that bypasses webpack's substitution. Node.js's native resolution already traverses ancestor node_modules directories, so the getAncestorNodeModules helper is no longer needed.

Test plan

  • Confirm existing read-yaml.spec.ts tests pass (the node_module resolution test at line 105 exercises this exact code path)
  • Manually test by opening a Shopify theme project in VS Code that uses a custom extends package in .theme-check.yml, verify no "Cannot find module" errors

Closes #1170

🤖 Generated with Claude Code

The VSCode extension server is bundled with webpack, which replaces
`require` with its own module system. webpack's `require.resolve` does
not support the `paths` option and returns a numeric module ID rather
than a file path, causing "Cannot find module" errors for custom check
packages (e.g. `@grafikr/theme-check-extension/recommended.yml`).

Replace `require.resolve(pathLike, { paths: getAncestorNodeModules(root) })`
with `createRequire` from `node:module`, which creates a real Node.js
require function that bypasses webpack's substitution. Node.js's native
module resolution already traverses ancestor node_modules directories
automatically, so `getAncestorNodeModules` is no longer needed.

Fixes Shopify#1170

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andershagbard andershagbard requested a review from a team as a code owner April 9, 2026 10:54
@andershagbard andershagbard marked this pull request as draft April 9, 2026 11:03
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andershagbard
Copy link
Copy Markdown
Contributor Author

I don't know how to test the VSCode extension. The build process seems to run in a loop for me

@andershagbard andershagbard marked this pull request as ready for review April 9, 2026 11:16
Copy link
Copy Markdown
Contributor

@aswamy aswamy left a comment

Choose a reason for hiding this comment

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

This is great stuff. I was able to use your theme-check in VSCode extension, and using the cli binary in theme-tools

Image Image

Comment thread packages/theme-check-node/src/config/resolve/read-yaml.ts Outdated
Comment thread packages/theme-check-node/src/config/resolve/read-yaml.ts Outdated
@aswamy
Copy link
Copy Markdown
Contributor

aswamy commented Apr 17, 2026

Thanks a lot @andershagbard for the fix. Merging this PR now 🙏. It should be part of the next patch for VSCode Extension. I think we just had one recently so look out for the next PR that looks like it when you want to see it released.

@aswamy aswamy merged commit 54e1418 into Shopify:main Apr 17, 2026
2 checks passed
@andershagbard
Copy link
Copy Markdown
Contributor Author

Thanks for quick review and merge 😄

@andershagbard andershagbard deleted the fix/vscode-node-modules-resolution branch April 17, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VSCode extension doesn't locate node_modules for custom checks package

2 participants