Issues when running under phantomjs #184
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#184
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I wrote a simple test ir run by phantomjs (Ubuntu):
test.js
Directory tree of phantomjs dir "phantomjs/bin":
Run-time error occurred:
TypeError: 'undefined' is not a constructor (evaluating 'new jszip(d, { base64:false })')
for the reason, I found in xlsx.js:
@machinewu Let's keep all of the relevant phantomjs issues to this discussion (I closed the other issue)
Can you check if
require('./jszip').JSZip
is defined in test.js?Also, with regards to the other issue, do you happen to know what is the correct way to detect if the script is being run in a phantomjs context? Clearly that part (fs detection and read/write semantics) needs to be reevaluated.
I change the xlsx.js
to
and run script test.js in phantomjs, it work.
so, I write some console log in xlsx.js to trace the jszip where it define by require. I found in phantomjs, it should not require: jszip = require('./js'+'zip').JSZip, but jszip = require('./js'+'zip')
The trace code:
result:
After change jszip = require('./js'+'zip').JSZip to jszip = require('./js'+'zip'):
The trace code:
result:
If I define JSZip at my code at first in phantomjs, It can work.
If I defined JSZip in a module but not global, it does not work.
test_module.js locate in the diretcory the same as test.js
Not work code:
test.js
test_module.js
Work code:
test.js
test_module.js
I think jszip should require more automatic, less manual require.
@machinewu last question: what happens if you use the xlsx.core.min.js file https://github.com/SheetJS/js-xlsx/blob/master/dist/xlsx.core.min.js in place of xlsx.js? When using this file, JSZip should not be pulled with
require
(it is defined so that entire code block is skipped)I change the name xlsx.core.min.js to xlsx.js, and replace the original xlsx.js. Remove jszip.js and dist/cpexcel.js.
test_module.js
Terminal display:
@machinewu thanks for looking into this! You've exposed quite a few interesting issues.
That workaround is in the code because the jszip.js script uses a different version from the nodejs module (there were quite a few problems when they stopped using https://github.com/imaya/zlib.js for DEFLATE). I will do some more tests in the browser with the latest version. If it works out, we can update the browser dependency and simplify the require logic
Hi all,
I'm also experiencing some issues, but in my case the message is different:
_TypeError: undefined is not a constructor (evaluating 'fs.readFileSync(data)')
I've installed xlsx via npm.
my code is:
Any thoughts?
Thanks,
Bruno
@brunoshine
Phantom.js dosen't have anIt seems like it have, sorry...fs
module and can't write to or read from disk.i am also having the same has there been a solution on this ?
function read_zip(data, opts) {
var zip, d = data;
var o = opts||{};
if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64";
switch(o.type) {
case "base64": zip = new jszip(d, { base64:true }); break;
case "binary": case "array": zip = new jszip(d, { base64:false }); break;
case "buffer": zip = new jszip(d); break;
case "file": zip=new jszip(d=_fs.readFileSync(data)); break;
default: throw new Error("Unrecognized type " + o.type);
xlsx.js:11374 Uncaught TypeError: undefined is not a function
The same thing:
var xlsx = require('./bower_components/js-xlsx/dist/xlsx.core.min.js');
var workbook = xlsx.XLSX.read(bstr, {type:"binary"});
first_sheet_name = workbook.SheetNames[0];
And response is:
TypeError: 'undefined' is not an object (evaluating 'xlsx.XLSX.read')
Is ti works with phantom?
I was having this issue using vanilla JS, I fixed it by making sure I included the scripts in the same order as the example.
How fix it on
react-native
context ?We are including a phantomjs sample based on @machinewu initial code in the next commit, as this appears to work in
2.1.1
. Please test and let us know if you have any other issues.@TechBK please raise a new issue if you are talking about something other than
phantomjs