nicolaspanel / numjs

Like NumPy, in JavaScript
MIT License
2.4k stars 184 forks source link

Add support for ES6 module #130

Closed WangNianyi2001 closed 1 year ago

WangNianyi2001 commented 2 years ago

As mentioned in issue #107, current numjs doesn't play well with ES6 module syntax. For example, trying to importing the whole package into an object will not work:

import * as nj from 'numjs'; // Could not find a declaration file for module 'numjs'.

And importing it directly will result in an error:

import 'numjs'; // Uncaught ReferenceError: global is not defined (pool.js:8:4)

The package is still using CommonJS-fashioned require & module.exports and is not supporting ES6 module at all! Please consider make it compatible with modules or provide another module-specified package.

ffind commented 2 years ago

@WangNianyi2001 try yarn add --dev @types/numjs Unfortunately types not perfectly working, lots of weird errors, but at least something

johndeighan commented 1 year ago

file:///C:/Users/johnd/ml/test/temp.js:8 ones, ^^^^ SyntaxError: Named export 'ones' not found. The requested module 'numjs' is a Co mmonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example usin g: