fossamagna / gas-webpack-plugin

Webpack plugin for Google Apps Script

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler errors with autoGlobalExportsFiles and webpack 5

enuchi opened this issue · comments

Hi @fossamagna, thanks for the work on this very useful plugin.

I've been trying to upgrade to webpack 5 and running into issues with autoGlobalExportsFiles config. It looks as though the "global" assignments are incorrectly being inserted into the webpack file.

I noticed when I take out this line, it works fine:

source.insert(source.size(), output.globalAssignments);

Here is my bundled file after I remove that line from this plugin. Interestingly, the code works fine if this line is left out -- I can still run this code in a spreadsheet and the global functions are found correctly:
Screen Shot 2022-06-12 at 11 56 14 AM

And here it is with that line left in. Notice the insertion is not happening in the right place.
Screen Shot 2022-06-12 at 11 56 47 AM

Any ideas what might be causing this?

Hi, @enuchi Thanks for submitting it. Is your project publicly available? I want to see how it is configured to understand how to solve this problem. If not, can you create a small repo on GitHub that replicates your project configuration ?

Thanks @fossamagna , yes just created small repo that replicates the issue here: https://github.com/enuchi/ts-loader-test

Run npm install and then npm run build -- it will create the file in dist/code.js. Note the malformed text replacement in the generated code on lines 70-72:

https://github.com/enuchi/ts-loader-test/blob/3ee1f076f8d9242e8af505b76be4f0769fee20fe/dist/code.js#L70-L72

Looks like the global assignment snippet that are generated are not being appended to the end of the code, but a little before and cut off the variable name. (And not sure if this global assignment is actually needed since the functions are exposed at global level.) Let me know if anything else looks off with the configuration. Thank you for the help on this!

I'm experiencing exactly same issue with autoGlobalExportsFiles option as @enuchi reported. I'm using CMD terminal in VS Code on Windows

image

As seen in the image above, letters get mingled when the plugin assigns global variables to "global' object, and interestingly, the way letters get mingled is slightly different when I build in WSL terminal in VS Code as below.

image

@enuchi Thank you for your repo. I can reproduce this issue.
I will address this issue.

@enuchi @SeraClinic

I have yet to find the root cause. However, the mode: none setting in webpack.config.js seems to be affecting this issue.
As a workaround, changing webpack.config.js as follows seems to prevent the issue.

  • Use production mode.
  • Set false to optimization.minimize (Optional, if you no need minify)

Hi @fossamagna, thanks again for looking into this issue.

Unfortunately changing to production mode didn't work fully for me. When I try running the build in production mode, the generated code seems correct in the sample repo (that is, no variables are being cut off), but when I try to run the script in the spreadsheet it still errors out. I tried running the build in production mode in a separate project that has a lot more functions, and the "global" assignments are still being inserted in the middle of a variable string, so it may just be an accident in the minimal repo that it "looks" correct in production mode.

The only way I could get it to work here is if I manually fix the generated code so that the "global" assignments are not cutting off any variables.

@enuchi Thank you for your feedback.
I published gas-webpack-plugin@2.2.2-beta.0. Would you be willing to try it?
I changed position of "global" assignments in this release.

Hi @fossamagna -- thanks so much for the fast change! The beta version appears to work with my tests, both in the sample repo and in another repo I am testing with. Please let me know if you plan to publish as a new full release.

Much appreciate for your hard work!! :)

Thanks again @fossamagna!!