Unable to import Math (sqrt) in Purescript

Hi everyone,
I am new to purescript and hence asking basic question.

While a run a code using pulp run command which has import Math (sqrt) command, I get below error. Kindly assist in resolving, I want to perform mathematical operations using purescript.

Error found:
in module Main
at src\Main.purs:3:1 - 3:19 (line 3, column 1 - line 3, column 19)

Module Math was not found.
Make sure the source file exists, and that it has been provided as an input to the compiler.

See documentation/errors/ModuleNotFound.md at master · purescript/documentation · GitHub for more information,
or to contribute content related to this error.

  • ERROR: Subcommand terminated with exit code 1

Hi,

the math package is deprecated - I think you are looking for the functionality in numbers.

It’d recommend using spago instead of pulp so the basic setup could look like this:

npm init -y
npm install --save-dev purescript spago
npx spago init
npx spago install numbers

from there you should be good to go - here is a npx spago repl session in this folder:

> import Data.Number (sqrt)
> sqrt 9.0
3.0
1 Like

On running npm install --save-dev purescript spago command, getting below error

npm WARN deprecated figgy-pudding@3.5.2: This module is no longer supported.
npm WARN deprecated @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs

purescript@0.15.15 postinstall C:\Users\satsa\my-finalproject\node_modules\purescript
install-purescript --purs-ver=0.15.15

√ Check if a prebuilt 0.15.15 binary is provided for win32-x64 (2s)
√ Download the prebuilt PureScript binary (1s)
√ Verify the prebuilt binary works correctly (5s)
√ Save the downloaded binary to the npm cache directory (468ms)

Installed to C:\Users\satsa\my-finalproject\node_modules\purescript\purs.bin 60.83 MB
Cached to C:\Users\satsa\AppData\Local\purescript-npm-installer-nodejs\Cache\content-v2\sha512\08\ad 60.83 MB

spago@0.21.0 postinstall C:\Users\satsa\my-finalproject\node_modules\spago
node ./install.js

internal/modules/cjs/loader.js:883
throw err;
^

Error: Cannot find module ‘node:events’
Require stack:

  • C:\Users\satsa\my-finalproject\node_modules\spago\node_modules\minipass-fetch\node_modules\minipass\dist\commonjs\index.js
  • C:\Users\satsa\my-finalproject\node_modules\spago\node_modules\minipass-fetch\lib\index.js
  • C:\Users\satsa\my-finalproject\node_modules\spago\node_modules\make-fetch-happen\lib\index.js
  • C:\Users\satsa\my-finalproject\node_modules\spago\install.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object. (C:\Users\satsa\my-finalproject\node_modules\spago\node_modules\minipass-fetch\node_modules\minipass\dist\commonjs\index.js:13:23)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions…js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [
    ‘C:\Users\satsa\my-finalproject\node_modules\spago\node_modules\minipass-fetch\node_modules\minipass\dist\commonjs\index.js’,
    ‘C:\Users\satsa\my-finalproject\node_modules\spago\node_modules\minipass-fetch\lib\index.js’,
    ‘C:\Users\satsa\my-finalproject\node_modules\spago\node_modules\make-fetch-happen\lib\index.js’,
    ‘C:\Users\satsa\my-finalproject\node_modules\spago\install.js’
    ]
    }
    npm WARN notsup Unsupported engine for make-fetch-happen@11.1.1: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: make-fetch-happen@11.1.1
    npm WARN notsup Unsupported engine for cacache@17.1.4: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: cacache@17.1.4
    npm WARN notsup Unsupported engine for minipass-fetch@3.0.5: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minipass-fetch@3.0.5
    npm WARN notsup Unsupported engine for ssri@10.0.6: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: ssri@10.0.6
    npm WARN notsup Unsupported engine for fs-minipass@3.0.3: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: fs-minipass@3.0.3
    npm WARN notsup Unsupported engine for glob@10.3.15: wanted: {“node”:“>=16 || 14 >=14.18”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: glob@10.3.15
    npm WARN notsup Unsupported engine for minipass@7.1.1: wanted: {“node”:“>=16 || 14 >=14.17”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minipass@7.1.1
    npm WARN notsup Unsupported engine for unique-filename@3.0.0: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: unique-filename@3.0.0
    npm WARN notsup Unsupported engine for @npmcli/fs@3.1.1: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: @npmcli/fs@3.1.1
    npm WARN notsup Unsupported engine for minipass@7.1.1: wanted: {“node”:“>=16 || 14 >=14.17”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minipass@7.1.1
    npm WARN notsup Unsupported engine for minipass@7.1.1: wanted: {“node”:“>=16 || 14 >=14.17”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minipass@7.1.1
    npm WARN notsup Unsupported engine for minimatch@9.0.4: wanted: {“node”:“>=16 || 14 >=14.17”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minimatch@9.0.4
    npm WARN notsup Unsupported engine for path-scurry@1.11.1: wanted: {“node”:“>=16 || 14 >=14.18”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: path-scurry@1.11.1
    npm WARN notsup Unsupported engine for minipass@7.1.1: wanted: {“node”:“>=16 || 14 >=14.17”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minipass@7.1.1
    npm WARN notsup Unsupported engine for minipass@7.1.1: wanted: {“node”:“>=16 || 14 >=14.17”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minipass@7.1.1
    npm WARN notsup Unsupported engine for unique-slug@4.0.0: wanted: {“node”:“^14.17.0 || ^16.13.0 || >=18.0.0”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: unique-slug@4.0.0
    npm WARN notsup Unsupported engine for minipass@7.1.1: wanted: {“node”:“>=16 || 14 >=14.17”} (current: {“node”:“14.16.1”,“npm”:“6.14.12”})
    npm WARN notsup Not compatible with your version of node/npm: minipass@7.1.1
    npm WARN my-finalproject@1.0.0 No description
    npm WARN my-finalproject@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! spago@0.21.0 postinstall: node ./install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the spago@0.21.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\satsa\AppData\Roaming\npm-cache_logs\2024-05-15T17_14_00_201Z-debug.log

Seems you have some issues with this package - this should be node.js related.
Did you install this by yourself?

If I read your output correctly you are on node.js 14 - this is probably a bit to old - is it possible for you to upgrade to current LTS (20) or some version mentioned in all the bound checks there?

1 Like