This is not an issue with this project, but rather than an Apps Script issue.
Long story short, if you are using template literals, and they contain symbols for comments, google will strip these at the time of rendering., ie, if building an url or something, everything after the // will be removed and break the code.
MRE:
const onOpen = (e) => {
DocumentApp.getUi() // Or SpreadsheetApp or SlidesApp or FormApp.
.createMenu('Broken Dialog')
.addItem('Open', 'openDialog')
.addToUi();
}
const openDialog = () => {
let markup = "<script>\n"
markup += "document.write('<h1>');\n"
markup += "document.write(`Apps Script is /*`);\n"
markup += "document.write(`fun and never*/ broken`);\n"
// this will throw an error in the console that is very hard to troubleshoot.
// markup += "document.write(`// sometimes`);\n"
markup += "document.write('</h1>');\n"
markup += "</script>\n"
const html = HtmlService.createHtmlOutput(markup)
.setWidth(800)
.setHeight(600);
DocumentApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Dialog title');
}
In my case, the issue was with firebase/auth, so I had to modify the webpack config to use babel-loader and add the '@babel/plugin-transform-template-literals' for all client js files. Something like:
const clientConfig = ({ isDevClientWrapper }) => ({
...sharedClientAndServerConfig,
mode: isProd ? 'production' : 'development',
output: {
path: destination,
// this file will get added to the html template inline
// and should be put in .claspignore so it is not pushed
filename: 'main.js',
publicPath,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
module: {
rules: [
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
use: [
{
loader: 'babel-loader',
options: {
compact: false,
plugins: [
'@babel/plugin-transform-template-literals',
!isProd &&
!isDevClientWrapper &&
require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
]
},
I am not very experienced with babel and webpack, so not sure if this is the best way to do it, but it worked.
This is not an issue with this project, but rather than an Apps Script issue.
Long story short, if you are using template literals, and they contain symbols for comments, google will strip these at the time of rendering., ie, if building an url or something, everything after the // will be removed and break the code.
MRE:
In my case, the issue was with firebase/auth, so I had to modify the webpack config to use babel-loader and add the
'@babel/plugin-transform-template-literals'for all client js files. Something like:I am not very experienced with babel and webpack, so not sure if this is the best way to do it, but it worked.