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

Cannot get Axios or Fetch to work in Clasp Upload #18

Closed MattisW closed 4 years ago

MattisW commented 4 years ago

Hi Labnol, thanks for the awesome work. I have setup the project as described in your youtube video and the setup works fine.

Now I want to work with Rest APIs and be able to work with the output both in Node.js as well as in the Google Sheets Addon I am building.

In order to do this, I am using Quokka.js + Node within VS Code for prototyping.

Given the following premises:

I decided to test out Fetch Polyfills (like cross-fetch) and axios + use babel-polyfill to handle promises, in order to allow the prototyping in node yet also get the same outcome in the browser.

Within node, everything works as expected, however once I add const axios = require('axios'); to any .js file in my project I receive the following error when trying to push the code via Clasp. code: 400, errors: [ { message: 'Syntax error: Missing name after . operator. line: ...., domain: 'global', reason: 'badRequest' } ] } On the given line throwing the error it states module.exports.default = axios; Once I comment out this line, the Clasp push works, but axios isn't working in the GAS environment.

Any ideas would be greatly appreciated! Best regards Mattis

labnol commented 4 years ago

This error likely happens when the npm library uses a dot before the default key.

Replace variable.default with variable["default"] and the error should be fixed.