[Patch][codegen]Add file extensions to generated import paths for Node16/NodeNext compatibility #2889
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
Fixes TypeScript compilation errors for users with Node16/NodeNext module resolution strategies.
Problem
Users with
moduleResolution: "Node16"or"NodeNext"in theirtsconfig.jsonwere getting compilation errors:This prevented them from building TypeScript projects using the generated GraphQL types without manual workarounds after every codegen run.
Solution
Modified the preset to include file extensions (
.d.tsor.ts) in generated import paths:import type * as AdminTypes from './admin.types';import type * as AdminTypes from './admin.types.d.ts';The fix:
options.baseOutputDirgetOutputFiles()helper to get the correct types filename with full extensiondeclarations: true(.d.tsfiles) anddeclarations: false(.tsfiles)Compatibility
bundlernodeNode16NodeNextCloses #2873
Testing
Steps to Reproduce the Bug
1. Create a New Shopify App
2. Modify tsconfig.json to Use NodeNext Module Resolution
Edit
tsconfig.jsonand change themoduleResolutiontoNodeNext:{ "include": ["env.d.ts", "**/*.ts", "**/*.tsx", ".react-router/types/**/*"], "compilerOptions": { "lib": ["DOM", "DOM.Iterable", "ES2022"], "strict": true, "skipLibCheck": false, // ⚠️ Change this to false to see the error "isolatedModules": true, "allowSyntheticDefaultImports": true, "removeComments": false, "forceConsistentCasingInFileNames": true, "noEmit": true, "allowJs": true, "resolveJsonModule": true, "jsx": "react-jsx", "module": "NodeNext", "moduleResolution": "NodeNext", // ⚠️ Change this from "Bundler" to "NodeNext" "target": "ES2022", "baseUrl": ".", "types": ["@react-router/node", "vite/client", "@shopify/polaris-types"], "rootDirs": [".", "./.react-router/types"] } }Key changes:
"moduleResolution": "NodeNext"(was"Bundler")"skipLibCheck": false(wastrue) - This is important to see the error!4. Run GraphQL Codegen
This will generate files in
./app/types/:admin.types.d.tsadmin.generated.d.tsadmin-2025-10.schema.json5. Verify the Bug Exists
Check the generated import in
app/types/admin.generated.d.ts:You should see (with the bug):
6. Run TypeScript to See the Error
npx tsc --noEmit --skipLibCheck falseYou should see the error:
Why this happens:
admin.types.d.tsfrom './admin.types'moduleResolution: "NodeNext", TypeScript requires explicit file extensions./admin.types→admin.types.d.tsSteps to Verify the Fix
1. Link the Fixed Local Version
Edit your app's
package.jsonand add the following (adjust path as needed):{ "devDependencies": { "@shopify/api-codegen-preset": "file:../shopify-app-js/packages/api-clients/api-codegen-preset", // ... other deps }, "resolutions": { "@shopify/api-codegen-preset": "file:../shopify-app-js/packages/api-clients/api-codegen-preset" }, "overrides": { "@shopify/api-codegen-preset": "file:../shopify-app-js/packages/api-clients/api-codegen-preset" } }Note: Adjust the path based on where your
shopify-app-jsrepo is located relative to your test app.2. Reinstall Dependencies
3. Clean and Regenerate Types
4. Verify the Fix
Check the generated import again:
You should now see (with the fix):
5. Verify TypeScript Compiles
npx tsc --noEmit --skipLibCheck falseThe
admin.typeserror should be gone! ✅