vite-ssg icon indicating copy to clipboard operation
vite-ssg copied to clipboard

Incorrect ssg build logic flow

Open nandi95 opened this issue 2 years ago • 0 comments

I have an issue that is quite odd and hard to understand. I cannot produce a reproduction repo at this time. The script builds fine for ssg but then when it requires the file I'm getting odd issues. First issue I had was that the bundle had this object that looked like this:

var require$$0 = {
  "name": (ctx) => {
    const { normalize: _normalize } = ctx;
    return _normalize(["axios"]);
  },
  "version": (ctx) => {
    const { normalize: _normalize } = ctx;
    return _normalize(["0.21.4"]);
  },
  .
  .
  .

(This seems like the whole of pkg json of axios) and this later was referenced as pkg.version.split('.') (pkg being an alias) which understandably failed. Then as I was looking through this repo I noticed the window mocking is done after we try to load the bundle, so I tried to move it beforehand and now the script succeds with the ssg build as well. However when trying to open this ssg output in the browser I'm getting the following error Uncaught TypeError: pc.version.split is not a function which looks just like what I saw in the in the main.js in the .vite-ssg-temp folder (the above example). In fact when I go into the minified file in the browser I can find this line pc={name:t=>{const{normalize:e}=t;return e(["axios"])},version:t=>{const{normalize:e}=t;return e(["0.21.4"])}.... which reminds me of the above.

This pkg.version.split('.') issue is probably not to do with this package but mocking the window should probably go before loading the bundle no?

nandi95 avatar Sep 23 '21 06:09 nandi95