1

I’m very new to node.js, and am just trying to learn the basics. I’m using the play.js IDE on my iPad and want to try some simple math-related javascript. I have successfully used jStat functions within the IDE, so I know that I can get it to work.

I’d like to use mathjs, so I’ve resolved the dependency in my test project, and my package.json now looks like this:

{
  "name": "test",
  "version": "1.0.0",
  "dependencies": {
    "jstat": "^1.9.3",
    "mathjs": "^7.2.0"
  }
}

The files all appear to be installed under the node_modules directory.

In my index.js, I just have the following example code straight from the mathjs help:

const { sqrt } = require('mathjs')

However, when I run this, I get the following error:

Uncaught TypeError: Cannot convert a Symbol value to a string
    at Array.join (<anonymous>)
    at Array.toString (<anonymous>)
    at Array.join (<anonymous>)
    at Array.toString (<anonymous>)
    at Array.join (<anonymous>)
    at Array.toString (<anonymous>)
    at mixkey (/private/var/mobile/Containers/Data/Application/8FF30C6F-8C40-4A4C-BA59-869F18430F8D/Documents/apps/TEST3FB8CAB9-FC43-4D65-9554-11E37599A1BB/src/node_modules/seed-random/index.js:135:25)
    at module.exports (/private/var/mobile/Containers/Data/Application/8FF30C6F-8C40-4A4C-BA59-869F18430F8D/Documents/apps/TEST3FB8CAB9-FC43-4D65-9554-11E37599A1BB/src/node_modules/seed-random/index.js:35:19)
    at /private/var/mobile/Containers/Data/Application/8FF30C6F-8C40-4A4C-BA59-869F18430F8D/Documents/apps/TEST3FB8CAB9-FC43-4D65-9554-11E37599A1BB/src/node_modules/mathjs/lib/function/probability/util/seededRNG.js:18:65

If it helps, that line in lib/function/probability/util/seededRNG.js looks like this:

var singletonRandom = /* #__PURE__ */(0, _seedRandom["default"])();

Am I doing something obviously wrong? Is there something I need to read to understand why this won’t run, or is this an issue with mathjs?

richarddmorey
  • 976
  • 6
  • 19
  • 1
    This error log goes into `seed-random` package. Can you try to use it separately from math.js? – Anton Sep 08 '20 at 18:08
  • @Anton the sole line `const sr = require('seed-random')` works fine, no error. – richarddmorey Sep 08 '20 at 18:16
  • 1
    @richarddmorey Can you think of something else that you did/configured? Is there another line of code in your `index.js` file? How are you trying to run your node code? There's something missing here as I have a working version of your setup. – stvn Sep 08 '20 at 18:24
  • @anton - actually, just tried adding the line `var a = sr()` and that resulted in the same error @stvn - no, that is literally the only line in `index.js`. Could it be something with how play.js sets up a project? I’m pretty new at this. – richarddmorey Sep 08 '20 at 18:34
  • 1
    oh, right. play.js. I'm not familiar with that and read over it in your problem description. Absolutely sure that that has something to do with it. – stvn Sep 08 '20 at 19:02
  • 1
    I did some research on play.js and apparently it still has limited support for node modules. One of the things I read is to try using a module bundler (like [browserify](http://browserify.org/) or [ncc](https://github.com/vercel/ncc)) to try and pack everything together and avoid module issues. Maybe you could give that a try. – stvn Sep 08 '20 at 19:05

0 Answers0