fix: use createRequire for node_modules resolution in VSCode extension#1171
Open
andershagbard wants to merge 2 commits intoShopify:mainfrom
Open
fix: use createRequire for node_modules resolution in VSCode extension#1171andershagbard wants to merge 2 commits intoShopify:mainfrom
andershagbard wants to merge 2 commits intoShopify:mainfrom
Conversation
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>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
I don't know how to test the VSCode extension. The build process seems to run in a loop for me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@grafikr/theme-check-extension/recommended.yml) fromnode_modules, while the CLI works fine.requirewith its own module system. webpack'srequire.resolveignores thepathsoption and returns a numeric module ID instead of a real file path.createRequirefromnode:moduleto create a proper Node.js require function that bypasses webpack's substitution. Node.js's native resolution already traverses ancestornode_modulesdirectories, so thegetAncestorNodeModuleshelper is no longer needed.Test plan
read-yaml.spec.tstests pass (the node_module resolution test at line 105 exercises this exact code path)extendspackage in.theme-check.yml, verify no "Cannot find module" errorsCloses #1170
🤖 Generated with Claude Code