New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alasql in browserify setup in the browser #583
Comments
Good point. The problem is found here - and your suggestion to a change makes a lot of sense. In #562 we are looking into making a central place to check for enviroment, so when its working we will replace the Would it be ok if I get back to you when we need to get it tested in browserify? |
yes, agree. NB: It is better to check if the |
Great, that you are already working on a solution based on a central environment detection. Yeah, checking if the |
NB: You can exclude modules in browserify config by marking them as "external resources" or by pointing to an empty js file and aliasing it to that file. Using isNode won't fix this, as both Webpack and Browserify use the AST and just pick up whatever has "require". UPDATE: Found this |
Exclude works well enough. |
First of all thank you for the fast corrections. But now I get the error Could it be because the check is for UPDATE: If I change the check to |
Wops.... please try this one instread: https://github.com/agershun/alasql/blob/develop/dist/alasql.js |
Thanks for the fix. The Promise error is gone, but now I get the following error: UPDATE: This seems to be due to the checking here |
Yeah, about time I add isNode/isWorker/isBrowser. |
@nowzig Please try again with https://github.com/agershun/alasql/blob/develop/dist/alasql.js @nickdeis I have included it as |
Should be fine for the most part. Kind of a fan of transitive values but that's the Java in me. |
transitive? |
Computed value. It's really only a valid pattern in a multithreaded environments since you always want to reinsure that the value is indeed correct. Even though I use stuff like Akka for multithreading, I still get punished for using fields sometimes. |
Ok. We are slowly getting there... AlaSQL uses js-xlsx library to read and export Excel files. Please include https://github.com/SheetJS/js-xlsx/blob/master/dist/xlsx.min.js update: and im working on |
Step by step it's getting better ;) I do now a For exporting a xlsx File I get I am also wondering wether there is a solution that alasql requires the libraries it depends on when it is used via browserify |
Oh boy... We are getting a lot of enviroment specifik things here. Lets hope we are solving more problems than we are introducing :) If you can tell me how I can find out that its running in a browersify setup, then we can navigate around it... |
Woops |
Could you do me a favor and run this in a browserify setup and tell me what is being printed to the log? var utils = {}
var getGlobal = function(){
try {
return Function('return this')();
}catch(e){
//If Content Security Policy
var global = self || window || global;
if(global){
return global;
} else {
throw new Error('Unable to locate global object');
}
}
}
utils.global = getGlobal();
var isNativeFunction = utils.isNativeFunction = function(fn){
return typeof fn === "function" && !!~(fn.toString().indexOf("[native code]"));
}
var isBrowser = function(){
try{
return utils.isNativeFunction(utils.global.location.reload);
}catch(e){
return false;
}
}
utils.isBrowser = isBrowser();
var isBrowserify = function(){
return utils.isBrowser && typeof exports === 'object';
}
utils.isBrowserify = isBrowserify();
console.log(JSON.stringify(utils, null, 4)); Update: updated code for errors |
I get a But if I am logging just the Maybe that is the information you want. UPDATE: I think it is possible to detect a browserify setup via UPDATE2: I corrected your code a bit, that the |
Ohh, I see - sorry for that. Cool. I think we have a way to solve it then |
@nowzig Ok - I cant figure out if browserify will be able to figure out that it should require XLSX - but try to run the latest https://github.com/agershun/alasql/blob/develop/dist/alasql.js where I let the utils.isBrowserify load XLSX same way as node, but handle saving a file same way as a browser... Update:
Ohh - only saw this now... changed the identification. |
Your suggested changes have been implemented in the latest build: https://github.com/agershun/alasql/blob/develop/dist/alasql.js |
Thanks for all your help and work. Because the One other thing, in 97saveas.js the check should be |
Great. The changes have been implemented in the latest build: https://github.com/agershun/alasql/blob/develop/dist/alasql.js |
It is now working perfectly. Thank you very much. |
Question: Is this statement works correct if return utils.isBrowser && process && process.browser; I think we should,to rewrite it with return utils.isBrowser && (typeof process !== "undefined") && process.browser; |
I will rewrite. Update: is |
👍 |
@agershun Did you see my question at 9045286#commitcomment-15945734 ? |
Sorry for delay, just answered. |
:) 👍 |
When doing importing or exporting of files (e.g. Excel) there is always an error like Uncaught TypeError: fs.writeFileSync is not a function
I use alasql with browserify in the browser.
I think it can be fixed by changing the checks like
if (typeof exports === 'object')
to
if (typeof exports === 'object' && process.browser !== true)
Maybe there is a better solution?
The text was updated successfully, but these errors were encountered: