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: webpack

The module is imported like any other node module. code

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

Most upvoted comments

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

<!DOCTYPE html>
<html>
<head>
  <title>math.js | issue #601</title>
</head>
<body>
  <script>
    // open the developer console in Chrome 58, 
    // and run this code until the debug point
    debugger;
    // when at the debug point, enter the following in the console:
    //
    //     var f = new Function ('a', 'return a + a');
    //     // f should be a function but is undefined when in debug mode
    // 
    //     console.log(f(2));   
    //     // should return 4, but throws "Uncaught TypeError: f is not a function"
    
    // without debug point, everything runs fine
    var f = new Function ('a', 'return a + a');
    console.log(f(2));
  </script>
</body>
</html>

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 if mathjs 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.