From the context7 docs, I now understand the CRITICAL issue:
Sandpack loads dependencies in two ways:
- External NPM packages - via
dependenciesin package.json - Local files/modules - via files in
/node_modules/directory in thefilesprop
I was trying to copy Formedible hooks and components from createFormedibleSandbox() directly into the sandbox files, but:
- The hooks import
@tanstack/react-form- this needs to be in package.json dependencies - The components depend on internal Formedible structure - these can't be resolved as external packages
- I broke the working system that was properly loading all the Formedible ecosystem
// LOCAL DEPENDENCIES GO IN /node_modules/
files: {
"/node_modules/my-library/package.json": JSON.stringify({
name: "my-library",
main: "./index.js"
}),
"/node_modules/my-library/index.js": "module.exports = { ... }",
"/App.js": `import { something } from "my-library"`
}
// EXTERNAL DEPENDENCIES GO IN customSetup
customSetup: {
dependencies: {
"@tanstack/react-form": "^0.38.1",
"react": "^18.2.0"
}
}The working system was:
- Using
createFormedibleSandbox()which contains ALL the Formedible components and hooks as/node_modules/entries - Proper package.json with all external dependencies like @tanstack/react-form
- Simple FormComponent that could import from the bundled Formedible modules
I replaced the working createFormedibleSandbox() system with:
- Direct file copying of hooks/components without proper
/node_modules/structure - Missing external dependencies in package.json
- Broken import paths trying to import internal files that don't exist in the sandbox
REVERT TO USING createFormedibleSandbox() which already handles:
- All Formedible components as proper
/node_modules/entries - Correct package.json with all external dependencies
- Proper file structure that Sandpack can resolve
ONLY CHANGE: The FormComponent generation to use JSON config with useFormedible instead of static components.
Looking at the build-time generation in sandbox-templates.json:
- The system generates 73 template files at build time
- These include all the Formedible ecosystem properly bundled for Sandpack
createFormedibleSandbox()uses this pre-built system
I completely misunderstood the Sandpack file loading system and destroyed a working dependency resolution by trying to copy files directly instead of using the proper /node_modules/ structure that was already working.