cazala / synaptic

architecture-free neural network library for node.js and the browser
http://caza.la/synaptic
Other
6.92k stars 666 forks source link

Following README.md => unexpected token export #256

Closed jcjollant closed 7 years ago

jcjollant commented 7 years ago

I am trying to use this lib with nodeJS v6.10.3 on Windows I followed the readme (npm+example) which gives the following:

C:\test\node_modules\synaptic\src\synaptic.js:1
(function (exports, require, module, __filename, __dirname) { export {default as
 Neuron} from './Neuron';
                                                              ^^^^^^
SyntaxError: Unexpected token export
    at createScript (vm.js:56:10)
    ...

The code is not too ambitious: var synaptic = require('synaptic');

Unless I am missing something obvious, instructions do not work.

fredylg commented 7 years ago

try this var synaptic = require(__dirname + '/dist/synaptic.js'); basicly make sure you have the proper path to it.

Loksly commented 7 years ago

another solution is just to install via:

npm install synaptic

like you already did, then the edit the node_modules/synaptic/package.json file, line 73, change the line

"main": "./src/synaptic",

to:

"main": "./dist/synaptic",
jcjollant commented 7 years ago

@fredylg __dirname was undefined, but it worked pointing directly at the dist synaptic.js . @Loksly I had the npm install, but not the package.json hack. It worked too and looks better in the code. Thank you both!

On top of these I had to prefix all my function calls with "synaptic" which is also missing from the doc. I still feel README.md should be fixed to mention these tricks.

cazala commented 7 years ago

Hi @jcjollant, this was due to the v1.1.0 release from 2 days ago. I just released a hotfix v1.1.1 where this is fixed. You can just bump the version in your dependencies to 1.1.1 and reinstall synaptic, it should be working