【问题标题】:How to import the googleapis npm package into meteor如何将googleapis npm包导入meteor
【发布时间】:2019-12-20 18:00:02
【问题描述】:

我正在使用流星框架,并尝试使用谷歌表格来可视化我的一些应用程序的数据。但无论出于何种原因,我似乎无法加载 google api。我从命令npm i googleapis 开始,然后添加const {google} = require('googleapis'),据我所知这是正确的。但是,当我console.log(google) 时,它会吐出undefined

我正在运行 Meteor 1.8.1、Node 6.12.0 和 googleapi ^39.2.0

我很想知道我做错了什么,大多数遇到此问题的人都需要更新各种其他软件包,所以我已经运行了 npm update 无济于事,我尝试使用 import { google } from 'googleapis' 也无济于事,我在某个地方看到了需要转换之类的东西,但它仍然吐出undefined

我注意到,如果我从我的流星外壳运行require('googleapis'),那么它会返回所有方法以及它应该返回的东西。

【问题讨论】:

    标签: node.js meteor google-api google-api-client


    【解决方案1】:

    好的,我该怎么做,以防止在我的 Meteor 项目中添加另一个 NPM ...

    在我的 main.html 中有这一行: <link rel="dns-prefetch" href="//maps.googleapis.com">

    下一个示例显示添加谷歌地图。我首先确保,在会话中,我最多加载这个库一次。

    由于需要 API,我在多个页面中调用此代码。由于我使用 react,所以我在 'componentDidMount' 中进行操作。

    if (!(window.google && window.google.maps)) {
          const script = document.createElement('script')
          script.src = 'https://maps.googleapis.com/maps/api/js?key=xxxxxxxxx&libraries=places'
          script.defer = true
          document.head.appendChild(script)
        }
    

    【讨论】:

      【解决方案2】:

      删除我的 node_modules 并运行 npm i 成功了

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-06-08
        • 2020-08-15
        • 1970-01-01
        • 1970-01-01
        • 2021-10-06
        • 2016-04-18
        • 2016-09-26
        相关资源
        最近更新 更多