mathjs: Unable to use math.js on frontend with webpack
Hello!
First off, koodos to author for a fantastic library.
I’m having trouble importing mathjs to frontend through webpack.
Whenever I import mathjs, here’s what happens:
The module is imported like any other node module.
And here’s my webpack config
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: ['./src/main.js'],
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
filename: 'build.js'
},
resolveLoader: {
root: path.join(__dirname, 'node_modules'),
},
module: {
loaders: [
{ test: /\.jade$/, loader: "jade" },
{
test: /\.js$/,
loader: 'babel',
include: [
path.resolve(__dirname, "src")
]
},
{ test: /\.json$/, loader: 'json' },
{ test: /\.vue$/, loader: 'vue' },
{ test: /\.scss$/, loaders: ["style", "css", "sass"], exclude: /node_modules/ },
{
test: /\.styl$/,
loaders: ["style", "css", "stylus"],
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url',
query: {
limit: 10000,
name: '[name].[ext]?[hash]'
}
}
]
},
devtool: 'eval-source-map'
}
module.exports.devtool = 'source-map'
// http://vuejs.github.io/vue-loader/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin()
])
No problems, however, using mathjs in node backend.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 34 (18 by maintainers)
Commits related to this issue
- Fixed #601: Issue with unnamed typed-functions by upgrading to typed-function v0.10.4 — committed to josdejong/mathjs by josdejong 8 years ago
- fix(project): switch to develop branch of math.js This fixes a Chrome specific issue with the library (josdejong/mathjs#601) and allows the use of proper minification. — committed to medja/ovs-prirocnik by medja 8 years ago
Ah, Thanks. I can reproduce this issue now. I’ve narrowed it quite a bit: it has not to do with angular, typescript or math.js, you can reproduce this issue in Chrome 58 with just one line of plain JavaScript:
http://jsbin.com/raluwu/edit?html,output
This might be a bug in Chrome 58. I’ve asked on stackoverflow: https://stackoverflow.com/questions/44228320/new-function-returns-undefined-in-chrome-58-when-in-debug-mode
good point @yogeshborad I suppose that this issue is resolved in math.js v4, since there
new Function
isn’t used anymore?I found an existing bug report on this issue: https://bugs.chromium.org/p/chromium/issues/detail?id=705149
Finally figured it out! The error only occurs if you’re debugging the application in the Chrome DevTools.
In the new
angular
4 application, I was testing ifmathjs
was working without fully implementing it, getting the error. In the demo, I just implemented it fully without debugging.Now, I can reproduce in both angularjs and angular (TypeScript).
I’ve updated both repositories. If you open:
With devtools open, you’ll get to a breakpoint with a comment that includes some code to execute. Executing this code in the debugging context will result in the error similar to the one that I described above.