【问题标题】:Can't import module into Node JS [duplicate]无法将模块导入 Node JS [重复]
【发布时间】:2021-09-25 23:25:49
【问题描述】:

我正在尝试将 tradingeconomics 模块导入节点 JS,但 Visual Code 正在强调该部分代码:

“找不到模块'tradingeconomics'的声明文件。'c:/Users/pc/node_modules/tradingeconomics/index.js'隐含了'any'类型。

尝试npm i --save-dev @types/tradingeconomics(如果存在)或添加包含declare module 'tradingeconomics'; 的新声明(.d.ts)文件

我尝试在控制台上运行“npm i --save-dev @types/tradingeconomics”,但它返回:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2ftradingeconomics - Not found
npm ERR! 404
npm ERR! 404  '@types/tradingeconomics@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\pc\AppData\Roaming\npm-cache\_logs\2021-07-17T13_56_44_617Z-debug.log

这是我尝试编写的代码,但没有返回任何内容。

const te = require('tradingeconomics');

te.login();

data = te.getIndicatorData().then(function(data){
    console.log(data)       
});

有人知道如何解决这个问题吗?

谢谢!

【问题讨论】:

    标签: javascript node.js api node-modules


    【解决方案1】:

    使用import { te } from 'tradingeconomics' 代替require()

    【讨论】:

      【解决方案2】:

      没有名为@types/tradingeconomics 的包。如果包只显示在您的 NPM 帐户中,则必须从命令行登录。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-07
        • 2021-09-27
        • 1970-01-01
        • 2021-10-22
        • 2021-04-13
        • 2016-06-28
        • 1970-01-01
        相关资源
        最近更新 更多