【问题标题】:mssql node js package not found when running azure function运行azure函数时找不到mssql节点js包
【发布时间】:2019-08-20 11:14:57
【问题描述】:

我正在尝试在本地连接 Azure 函数中的 SQL 服务器, 我收到以下错误,

[error] Worker was unable to load function timerTriggerWithEventHub: 'Error: Cannot find module 'mssql''

但是我的机器上已经安装了mssql包,

这是我的代码,

const sql = require('mssql').Request;
module.exports = async function (context, myTimer) {
    var config = {
        user: 'sa',
        password: 'Gain@123',
        server: 'DESKTOP-J7IPQ7H', 
        database: 'RealTimeProductSales' 
    };
    sql.connect(config, function (err) {    
        if (err) console.log(err);
        // create Request object
        var request = new Request();           
        // query to the database and get the records
        request.query('select * from dbo.ProdTC', function (err, recordset) {            
            if (err) console.log(err)
            console.log(recordset)
            // send records as a response
            // res.send(recordset);

        });
    });

    // console.log('saranraj')
    // console.log(context,myTimer)
    // var timeStamp = new Date().toISOString();

    // if (myTimer.IsPastDue)
    // {
    //     context.log('JavaScript is running late!');
    // }
    // context.log('JavaScript timer trigger function ran!', timeStamp);   
    // return "{'name':'saran'}"
};

当我安装软件包时,我得到这样的输出

npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\SivaSakthiVelan\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\SivaSakthiVelan\package.json'
npm WARN SivaSakthiVelan No description
npm WARN SivaSakthiVelan No repository field.
npm WARN SivaSakthiVelan No README data
npm WARN SivaSakthiVelan No license field.

+ mssql@5.1.0
updated 1 package and audited 11650 packages in 6.832s
found 226 vulnerabilities (42 moderate, 184 high)
  run `npm audit fix` to fix them, or `npm audit` for details

【问题讨论】:

    标签: node.js sql-server azure-functions azure-app-service-plans azure-functions-core-tools


    【解决方案1】:

    好像 package.json 不见了。

    您可以尝试运行以下命令:

    npm init -f
    

    上面的这个命令将帮助你初始化一个 package.json(-f 表示强制)。

    您可以检查 package.json 中的依赖关系。

    然后运行下面的命令:

    npm install mssql
    

    【讨论】:

    • 嗨@saran,我想知道这个答案是否对您的问题有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 2017-05-27
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多