hyperbrew / vite-cep-plugin

A Vite plugin to build Adobe CEP Extension Panels
MIT License
16 stars 16 forks source link

Error generating bundle #9

Closed timhaywood closed 2 years ago

timhaywood commented 2 years ago

Related to #8

On build Vite exits during generating the bundle, due to an error in the plugin.

[cep] Cannot read property 'replace' of undefined
error during build:
TypeError: Cannot read property 'replace' of undefined

For me it was line 254 where it's replacing fixing the /assets/ paths in .js files.

I haven't dove in enough to understand the full context, but it seems that some .js files don't contain a code property. These are the available keys of the file that it errors on:

[ 'fileName', 'isAsset', 'name', 'source', 'type' ];

Simply checking .code exists worked for me:

      if (bundle[jsFilename].code) {
        // fix paths
        bundle[jsFileName].code = bundle[jsFileName].code.replace(
          /(\/assets\/)/g,
          "../assets/"
        );
      }

Created draft fix #10

justintaylor-dev commented 2 years ago

Thanks! Fixed in 0.1.6 and onward

timhaywood commented 2 years ago

Amazing, thanks Justin!