Strangely enough the Chrome/Electron devtools debugger shows loadDataset as defined inside the function project:
It is not in the function locals, but it is in the parent closure:
| // A simple module. One function uses a function defined in the same file. | |
| // Easy as pie | |
| function project(functions, path, statsParams, mapParams) { | |
| // Undefined reference: loadDataset is not defined | |
| return loadDataset(path, functions, statsParams).then(dataset => { | |
| // etc | |
| // return mapDataset(functions, mapParams, dataset); | |
| }); | |
| } | |
| function loadDataset(path, functions, statsParams) { | |
| return new Promise(); // implementation goes here | |
| } | |
| module.exports = { | |
| project, | |
| loadDataset | |
| }; | |
| // using this with node on the commandline works without any problem | |
| const dp = require('data-projector'); | |
| // module exports everything correctly | |
| console.log(dp); | |
| // yes, of course it's defined | |
| console.log(dp.loadDataset); | |
| // yep, it works | |
| dp | |
| .project( | |
| {}, | |
| '/Users/crucial/code/idmx/playsplom/app/vendor/datasets/seals.csv', | |
| {}, | |
| { | |
| lat: { | |
| fn: (s, f, v) => v * 2 | |
| }, | |
| long: { | |
| fn: (s, f, v) => v * 2 | |
| } | |
| } | |
| ) | |
| .then(console.log, console.error); |
| const dp = require('data-projector'); | |
| console.log(dp); | |
| // yes, its defined ... | |
| console.log(dp.loadDataset); | |
| // but when loadDataset is called by the function project it is undefined within that function ! | |
| dp | |
| .project( | |
| {}, | |
| '/Users/crucial/code/idmx/playsplom/app/vendor/datasets/seals.csv', | |
| {}, | |
| { | |
| lat: { | |
| fn: (s, f, v) => v * 2 | |
| }, | |
| long: { | |
| fn: (s, f, v) => v * 2 | |
| } | |
| } | |
| ) | |
| .then(console.log, e => { | |
| // Undefined reference. loadDataset is not defined | |
| console.error('dp failed', e); | |
| }); | |
| // this is causing the problem: | |
| config.devtool = 'cheap-module-eval-source-map'; | |
| // This works fine | |
| // config.devtool = 'source-map'; | |
| /** | |
| I haven't upgraded this project to webpack 2, | |
| so maybe this is long ago solved. | |
| "webpack": "^1.13.2", | |
| "source-map-support": "^0.4.5", | |
| "webpack-dev-middleware": "^1.8.4", | |
| "webpack-hot-middleware": "^2.13.0" | |
| **/ |