Closed kevlened closed 8 months ago
The solution involves ensuring that the vitePluginArraybuffer
does not interfere with Vite's default module resolution, particularly for modules like /react/jsx-runtime
. Since the error message indicates a problem with module resolution, we need to verify that the plugin is not mistakenly capturing or altering requests for the React JSX runtime module. We should also check for any updates to Vite's plugin API that could affect how plugins should handle module resolution, especially with the introduction of Vite in Remix.
The bug is likely caused by a conflict between the vitePluginArraybuffer
and Vite's module resolution mechanism. Since the error occurs when trying to load /react/jsx-runtime
, it's possible that the plugin is either incorrectly handling the resolution of this module or that changes in Vite's API or Remix's integration with Vite have introduced new requirements for plugin compatibility that the vitePluginArraybuffer
does not yet meet.
To address the issue, we need to review and potentially update the resolveId
and transform
functions in src/main.ts
. We should add checks to ensure that the plugin does not interfere with the resolution of modules that it is not intended to handle, such as /react/jsx-runtime
.
// src/main.ts
export default function vitePluginArraybuffer() {
return {
name: 'vite-plugin-arraybuffer',
resolveId(source, importer, options) {
// Add a check to ensure that the plugin does not interfere with React JSX runtime resolution
if (source === '/react/jsx-runtime') {
return null; // This tells Vite to handle the resolution as it normally would
}
// Existing logic for handling '?arraybuffer' and '?uint8array' goes here...
},
transform(code, id) {
// Existing logic for transforming matched files goes here...
},
// Additional plugin hooks or configuration may be added here if necessary
};
}
To replicate the bug, set up a Remix project that uses Vite as the build tool. Then, install the plugin version 0.0.4 and attempt to build the project. The error should occur during the build process, specifically when Vite tries to load the /react/jsx-runtime
module.
The task is to ensure that the vitePluginArraybuffer
is compatible with the latest version of Vite used by Remix and does not interfere with the resolution of modules it is not designed to handle. This involves reviewing and updating the plugin's resolveId
and transform
functions to respect Vite's default module resolution process, especially for critical modules like the React JSX runtime.
Click here to create a Pull Request with the proposed solution
Files used for this task:
The autopilot doesn't offer a good solution. Ideally, this plugin is inert if it's not transforming a file. Returning false
isn't inert in resolveId
.
Returning false signals that source should be treated as an external module and not included in the bundle source
The autopilot doesn't offer a good solution. Ideally, this plugin is inert if it's not transforming a file. Returning
false
isn't inert inresolveId
.Returning false signals that source should be treated as an external module and not included in the bundle source
Thank you for pointing that out. You're correct that returning false
from resolveId
would treat the module as external, which is not the intended behavior. Instead, the plugin should return null
or undefined
to indicate that it doesn't want to handle the resolution of the module, allowing Vite to continue its normal resolution process.
Here's the updated resolveId
function:
// src/main.ts
export default function vitePluginArraybuffer() {
return {
name: 'vite-plugin-arraybuffer',
resolveId(source, importer, options) {
// Check if the source ends with '?arraybuffer' or '?uint8array'
if (source.endsWith('?arraybuffer') || source.endsWith('?uint8array')) {
// Handle the resolution for these specific cases
// Existing logic for handling '?arraybuffer' and '?uint8array' goes here...
} else {
// For all other cases, do not interfere with the resolution
return null; // This tells Vite to handle the resolution as it normally would
}
},
transform(code, id) {
// Existing logic for transforming matched files goes here...
},
// Additional plugin hooks or configuration may be added here if necessary
};
}
This change should ensure that the plugin is inert for any imports that do not match its specific use case, allowing Vite to resolve /react/jsx-runtime
and other modules correctly.
Does version 0.0.5 solve your problem?
It does! Thanks
Remix now uses Vite. When using this plugin in the Vite build, it fails with:
Error: [vite:load-fallback] Could not load /react/jsx-runtime (imported by app/routes/test/route.tsx): ENOENT: no such file or directory, open '/react/jsx-runtime'
This doesn't happen on version 0.0.2