Skip to content

Instantly share code, notes, and snippets.

@crucialfelix
Last active May 3, 2017 09:32
Show Gist options
  • Select an option

  • Save crucialfelix/f61b01f2f306eb14c97496e7a01e9ff5 to your computer and use it in GitHub Desktop.

Select an option

Save crucialfelix/f61b01f2f306eb14c97496e7a01e9ff5 to your computer and use it in GitHub Desktop.
webpack 1 : cheap-module-eval-source-map causes Reference undefined
// 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"
**/

Strangely enough the Chrome/Electron devtools debugger shows loadDataset as defined inside the function project:

is defined

It is not in the function locals, but it is in the parent closure:

imgurl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment