-
Notifications
You must be signed in to change notification settings - Fork 10
ReferenceError: __VITE_PRELOAD__ is not defined #13
Comments
can you support a reproduce demo ? |
Easiest reproduction is probably: import foo from './foo.js'
import('./foo.js');
console.log(foo); Here is a repro: https://github.com/eigan/repro-vite-dynamic-publicpath Commited the build file with the constant still present https://github.com/eigan/repro-vite-dynamic-publicpath/blob/master/dist/assets/app.09997e2f.js |
Probably relevant code in Vite: // there may still be markers due to inlined dynamic imports, remove
// all the markers regardless
chunk.code = chunk.code.replace(preloadMarkerRE, 'void 0') |
@jy0529 need reproduce label can be removed I think? |
I'm having this issue as well now in my personal projects. |
I'd like to mention that it still breaks in the latest version of vite (as of this time: |
I hate to bump, but @jy0529 any chance we get a fix for this? |
@benjaminprojas Not sure what you expected to be fixed in vite 2.9, but vite 3 might fix an issue that sent me here to This PR vitejs/vite#8450 might replace this plugin completely. |
@eigan Vite v3 is out, have you gotten a chance to try that new feature out (docs: https://vitejs.dev/guide/build.html#advanced-base-options)? I'm trying it out, but I can't get it to work. Edit: Nevermind!! I got it: experimental: {
renderBuiltUrl: (filename, { hostType }) => {
if (hostType === 'js') {
return { runtime: `window.__dynamicImportPreload__(${JSON.stringify(filename)})` }
} else {
return { relative: true }
}
},
} And then in the window.__dynamicImportPreload__ = function(filename: string) {
return `whateverPrefix/${filename}`;
}; |
@francislavoie Haven't tested yet. But thanks for testing and giving us a solution! 🙂 |
There is some places where the plugin will leave
__VITE_PRELOAD__
present in the build.See example:
Without plugin
With plugin
Temporary solution
Main file:
__dynamicImportHandler__
and__dynamicImportPreload__
must now handle when first argument is undefined.The text was updated successfully, but these errors were encountered: