Wednesday, 10 May 2017

Coffee-Script Error in React App on importing external function(JS Google Api)

I created a simple app by following this document create-react-app

and it works great! Then i want to use google's api in js as you can read here

by importing "Option 1" script. I've tested it in a html file and it worked. So, i want to use that js script in my react app(for example calling 'start()' function onclick, i know how to do that). I tried: import {start} from './apiCall'; var gapi = require('gapi');

where apiCall is my js:

export function start() {
  // 2. Initialize the JavaScript client library.
  gapi.client.init({
    'apiKey': 'YOUR_API_KEY',
    // Your API key will be automatically added to the Discovery Document URLs.
    'discoveryDocs': ['https://people.googleapis.com/$discovery/rest'],
    // clientId and scope are optional if auth is not required.
    'clientId': 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com',
    'scope': 'profile',
  }).then(function() {
    // 3. Initialize and make the API request.
    return gapi.client.people.people.get({
      resourceName: 'people/me'
    });
  }).then(function(response) {
    console.log(response.result);
  }, function(reason) {
    console.log('Error: ' + reason.result.error.message);
  });
};
// 1. Load the JavaScript client library.
gapi.load('client', start);

At this point i get a lot of Coffee-Script errors:

Error in ./~/coffee-script/lib/coffee-script/coffee-script.js
Module not found: 'module' in C:\Users\Lavoro\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script

Error in ./~/coffee-script/lib/coffee-script/register.js
Module not found: 'child_process' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script

Error in ./~/coffee-script/lib/coffee-script/register.js
Module not found: 'module' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script

Module not found: 'child_process' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script

Error in ./~/coffee-script/lib/coffee-script/grammar.js
Module not found: 'jison' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script

Error in ./~/coffee-script/lib/coffee-script/repl.js
Module not found: 'repl' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script

How can i import an external function (in this case GAPI function) correctly?



via Valerio Marzulli

No comments:

Post a Comment