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

Failing since updating this package from 4.1.1 to 4.2.2 #1101

Closed
SimonSimCity opened this Issue May 7, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@SimonSimCity

SimonSimCity commented May 7, 2018

Today I've updated my package to MathJS v4.2.2 and found this error when trying to start it:

ReferenceError: window is not defined
    at Object.<anonymous> (/projects/test/node_modules/mathjs/dist/math.js:38:4)

I can confirm that it worked with MathJS v4.1.1 so I'm for now switching back to it ...

Don't know how much it has to say, but I'm using your library in a Meteor project.

@josdejong

This comment has been minimized.

Owner

josdejong commented May 7, 2018

Thanks for reporting @SimonSimCity .

I think this could be related to changed behavior in webpack, which was upgraded from v3.3.11 to v4.6.0 in mathjs@4.2.0 (see history, see commit). Haven't looked into it yet.

@josdejong

This comment has been minimized.

Owner

josdejong commented May 7, 2018

@SimonSimCity how can I reproduce this issue? Do you have some minimalist setup/demo which replicates the issue?

@jackschmidt

This comment has been minimized.

Contributor

jackschmidt commented May 8, 2018

I found two reproducers.

In node, if I do math=require('mathjs/dist/math.js') then I get this error. However, if I do the more reasonable math=require('mathjs') everything is fine.

In a browser, if I do importScript('https://cdnjs.cloudflare.com/ajax/libs/mathjs/4.2.2/math.min.js') from within a Web Worker, I also get the error. (So create a short js file worker.js with that line in it, then from within the browser call new Worker('worker.js') to get the error.)

It does seem like dist/math.js has a misnamed "universalModuleDefinition" since it doesn't work in workers or node.

@josdejong josdejong closed this in 9b5596f May 21, 2018

@josdejong

This comment has been minimized.

Owner

josdejong commented May 21, 2018

This seems to be an issue in webpack 4, see webpack/webpack#6642

I've solved it by adding globalObject: 'this' to the webpack config, and the bundle seems to work fine now in the browser, WebWorkers, and node.js.

@jackschmidt would be great if you can verify whether this issue is solved in mathjs v4.3.0.

@jackschmidt

This comment has been minimized.

Contributor

jackschmidt commented May 21, 2018

Looks good in browser, web workers, and node when installed from npm (and unpkg, jsdelivr for browser and workers).

@josdejong

This comment has been minimized.

Owner

josdejong commented May 21, 2018

👍 thanks for the fast feedback.

@SimonSimCity

This comment has been minimized.

SimonSimCity commented Jun 7, 2018

Sorry for the very belayed response ... I too can confirm it works again with the latest version 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment