Skip to content

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

@MattisW

Description

@MattisW

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:

  • Node doesn't support UrlFetchApp.fetch
  • GAS doesn't support native fetch (due to lack of the window and dom objects)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions