jsreport / jsreport-core

The minimalist jsreport rendering core
GNU Lesser General Public License v3.0
86 stars 24 forks source link

"Bad argument" error #21

Closed eczajk1 closed 7 years ago

eczajk1 commented 7 years ago

I am receiving the following error when trying to run the "Quick Example" shown on the readme:

internal/child_process.js:290
  var err = this._handle.spawn(options);
                         ^

TypeError: Bad argument
    at TypeError (native)
    at ChildProcess.spawn (internal/child_process.js:290:26)
    at exports.spawn (child_process.js:365:9)
    at Object.exports.execFile (child_process.js:139:15)
    at d:\redacted\node_modules\jsreport-phantom-pdf\node_modules\phantom-html-to-pdf\lib\dedicatedProcessStrategy.js:47:34
    at d:\redacted\node_modules\graceful-fs\graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:82:15)

I am on Windows.

bjrmatos commented 7 years ago

hi!

i guess that you are using the following steps and code, right?:

npm install jsreport-core npm install jsreport-jsrender npm install jsreport-phantom-pdf

var jsreport = require('jsreport-core')()

jsreport.init().then(function () {     
   return jsreport.render({
       template: {
           content: '<h1>Hello {{:foo}}</h1>',
           engine: 'jsrender',
           recipe: 'phantom-pdf'
        },
        data: {
            foo: "world"
        }
    }).then(function(resp) {
     //prints pdf with headline Hello world
     console.log(resp.content.toString())
   });
}).catch(function(e) {
  console.log(e)
})

if this is the same code that you are using then i would say that probably something went wrong in the npm installation (when phantomjs was downloaded), probably a quick test can be to delete your node_modules folder an try to reinstall everything, before you reinstall everything run this: npm cache clean to ensure that there won't be any corrupted temp file in npm's cache.

another cause can be that when phantomjs is installed your directory does not have the right permission to extract internal zip file that contains the phantomjs executable. what is the directory of your project? when re-installing you can also try to run the installation in an elevated command prompt with administrative privileges, a.k.a "Run as administrator"

eczajk1 commented 7 years ago

Yes, that is the same code I was using. And yes, it looks like something was wrong with the phantomjs installation. I just tried the sample in a fresh directory and it worked as expected.

Thanks! 👍