labnol / apps-script-starter

Setup a local development environment inside Visual Studio Code and build Google Workspace add-ons with Google Apps Script
https://www.youtube.com/watch?v=KxdCIbeO4Uk
MIT License
1.1k stars 176 forks source link

functions in file with imports can't be created in webpack production mode #64

Closed dhlin closed 1 year ago

dhlin commented 1 year ago

Steps to reproduce

Run the following commands:

git clone https://github.com/labnol/apps-script-starter test-apps-script cd test-apps-script add file testimport.js with below content under src/server folder and import it in src/index.js

  import { makeQueryString } from './http';

global.testimport = () => {
    const url = makeQueryString('https://google.com');
    Logger.log(`Query string is ${url}`);
};

npm install npm run build

Actual Result

in code.js, the new function definition is not created. The new function is not created in the apps script after deploy

function sendmail() {}
function showHelp() {}
function showCredits() {}
function onOpen() {}
function doGet() {}
...

Expected Result

function sendmail() {}
function showHelp() {}
function showCredits() {}
function onOpen() {}
function doGet() {}
function testimport() {}
...

Turn the webpack mode to none fix the problem. Functions in file without imports also do not have this problem in both mode. Is there a fix to support this in production mode?

labnol commented 1 year ago

The newest release fixes the issue.

https://github.com/labnol/apps-script-starter/blob/e47451ddbe174954e36f6e5771f01921dc225865/src/index.js