babel / babel/gulp-babel

When used with gulp-source-maps build fails with error "Path must be a string. Received undefined"

Open
#154 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.3k
Forks
113
PR merge metrics
No merged PRs in 30d

Description

After updating my node to "v8.11.1" and npm to "5.6.0" gulp build gets broken if used with "gulp-source-maps"

Here is my gulpfile:
```
"use strict";

let tabReloaderInstance,
gulp = require("gulp"),
gulpSourcemaps = require("gulp-sourcemaps"),
mergeStream = require("merge-stream"),
yargs = require("yargs"),

argv = yargs.argv,
rootPath = argv.JenkinsCartridgesPath || __dirname,

// Babel
babel = require("gulp-babel"),
gulpBrowserify = require("gulp-browserify"),
es2015 = require("babel-preset-es2015");

/* JavaScript paths */
var JS_PATHS = [
{
"wtc" : "int_acf_core/cartridge/js/**/*.js",
"src" : "int_acf_core/cartridge/js/modules_system.js",
"dst" : "int_acf_core/cartridge/static/default/js"
}
];

// generate js
gulp.task("js", () => {
var streams = mergeStream();
var optBrfy = {"debug" : true}

// Needed when task is run from Jenkins so that Browserify can resolve the modules installed with NPM
if (argv.JenkinsBuild) {
optBrfy = xtend(optBrfy, {"paths" : [argv.JenkinsNodeModulesPath]});
}

JS_PATHS.forEach(function(p) {
var srcPath = path.join(rootPath, p.src),
dstPath = path.join(rootPath, p.dst);

streams.add(gulp.src(srcPath)
.pipe(gulpBrowserify(optBrfy))
.pipe(gulpSourcemaps.init())
.pipe(babel({
presets: [es2015]
}))
.pipe(gulpSourcemaps.write('./'))
.pipe(gulp.dest(dstPath)));
});

return streams;
});
```

js task fails with error "Path must be a string. Received undefined"

I traced the error to "node_modules/gulp-babel/index.js"
line 39

where you gulp-babel has following code as this point:
```
if (file.sourceMap && res.map) {
res.map.file = replaceExtension(res.map.file);
applySourceMap(file, res.map);
}
```

Problem is that res.map.file here is undefined even though file.sourceMap and res.map has big JSON objects returned.

this breaks the build.
Before update this setup was working properly.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the gulpfile's js task and reproduce the failure using gulp-browserify, gulp-sourcemaps, gulp-babel, Node v8.11.1, and npm 5.6.0. Inspect node_modules/gulp-babel/index.js at line 39 and trace why res.map.file is undefined when the source map is applied. Done means the js task builds successfully with source maps enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript, node.js
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.