Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Heroku上的svg2png-类型错误:错误参数_Node.js_Heroku_Promise - Fatal编程技术网

Node.js Heroku上的svg2png-类型错误:错误参数

Node.js Heroku上的svg2png-类型错误:错误参数,node.js,heroku,promise,Node.js,Heroku,Promise,我对Heroku上的SVG2NG包有问题。它可以在我的本地机器(Windows)上运行,但我无法让它在免费dyno和付费dyno(嗜好和标准x1)上运行 其想法是从维基百科获取svg并将其作为png返回。我已经公开了两个端点: /-使用存储在单独文件中的代码 /简单-相同的代码,但只是在回调中 浏览两个端点时,我会收到Heroku应用程序错误页面。这就是我在Heroku日志中看到的两个请求: Bad argument TypeError: Bad argument at exports.s

我对Heroku上的SVG2NG包有问题。它可以在我的本地机器(Windows)上运行,但我无法让它在免费dyno和付费dyno(嗜好和标准x1)上运行

其想法是从维基百科获取svg并将其作为png返回。我已经公开了两个端点:

  • /-使用存储在单独文件中的代码
  • /简单-相同的代码,但只是在回调中
浏览两个端点时,我会收到Heroku应用程序错误页面。这就是我在Heroku日志中看到的两个请求:

Bad argument TypeError: Bad argument
 at exports.spawn (child_process.js:378:9)
 at Object.execFile (/app/node_modules/pn/_promisify.js:35:27)
 at TypeError (native)
 at ChildProcess.spawn (internal/child_process.js:294:26)
 at Object.exports.execFile (child_process.js:143:15)
 at Promise.resolve.then (/app/node_modules/svg2png/lib/svg2png.js:13:33)
 at process._tickCallback (internal/process/next_tick.js:109:7)
你有什么想法吗

index.js

const svg2png = require('svg2png')
const axios = require('axios')
const express = require('express')
const bodyParser = require('body-parser')
const conv = require('./conv')

const svgUrl = 'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg'

const app = express()

app.use(bodyParser.json({limit:'5mb'}))
app.use(bodyParser.urlencoded({extended:true,limit:'5mb'}))

app.get('/simple', function (req, res) {
    axios.get(svgUrl)
        .then(response => {
            return svg2png(response.data, { width: 150, height: 150 })
        })
        .then(pngFile => {
            var img = new Buffer(pngFile, 'base64')
            res.writeHead(200, {
                'Content-Type': 'image/png',
     'Content-Length': img.length
            })
            res.end(img)
        })
})

app.get('/', function (req, res) {
conv.send()    
        .then(pngFile => {
            var img = new Buffer(pngFile, 'base64')
            res.writeHead(200, {
                'Content-Type': 'image/png',
     'Content-Length': img.length
            })
            res.end(img)
        })
})

app.listen(process.env.PORT || 5000, function () {
    console.log('Application started')
})
const axios = require('axios')
const svg2png = require('svg2png')

module.exports = {
    send() {
        const self = this;
                self.width = 300;
        self.height = 300;

        const svgUrl = 'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg'
        return new Promise((resolve, reject) => {
            axios.get(svgUrl)
            .then(response => 

            svg2png(response.data,
             { width: self.width, height: self.height })
            .then(img=>resolve(img))
            .catch(e => {
                console.log('Something went wrong during svg2png conversion.' + e)
                reject(e)
            }))
        });

    }
}
conv.js

const svg2png = require('svg2png')
const axios = require('axios')
const express = require('express')
const bodyParser = require('body-parser')
const conv = require('./conv')

const svgUrl = 'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg'

const app = express()

app.use(bodyParser.json({limit:'5mb'}))
app.use(bodyParser.urlencoded({extended:true,limit:'5mb'}))

app.get('/simple', function (req, res) {
    axios.get(svgUrl)
        .then(response => {
            return svg2png(response.data, { width: 150, height: 150 })
        })
        .then(pngFile => {
            var img = new Buffer(pngFile, 'base64')
            res.writeHead(200, {
                'Content-Type': 'image/png',
     'Content-Length': img.length
            })
            res.end(img)
        })
})

app.get('/', function (req, res) {
conv.send()    
        .then(pngFile => {
            var img = new Buffer(pngFile, 'base64')
            res.writeHead(200, {
                'Content-Type': 'image/png',
     'Content-Length': img.length
            })
            res.end(img)
        })
})

app.listen(process.env.PORT || 5000, function () {
    console.log('Application started')
})
const axios = require('axios')
const svg2png = require('svg2png')

module.exports = {
    send() {
        const self = this;
                self.width = 300;
        self.height = 300;

        const svgUrl = 'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg'
        return new Promise((resolve, reject) => {
            axios.get(svgUrl)
            .then(response => 

            svg2png(response.data,
             { width: self.width, height: self.height })
            .then(img=>resolve(img))
            .catch(e => {
                console.log('Something went wrong during svg2png conversion.' + e)
                reject(e)
            }))
        });

    }
}

Heroku日志是否有关于哪一行可能导致
类型错误的更多信息?这将使追踪问题所在变得更容易。@bouteillebleu,我已经更新了帖子,粘贴了完整的错误消息。当我使用catch()方法进行日志记录时,我发现问题出在svg2png中(假设我正确地链接了promise方法…)。