google / google/closure-compiler
Problem with relative references (specifically parent) within node modules?
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
__NOTE__: X-POSTED from google/closure-compiler-npm#70
Just wondering if there is an issue where a dependency brought in via a node module has trouble resolving a file that sits in the parent directory of the current file being processed. A good example of this is the the "fp" variants of the `lodash` functions. For example, shown below is the contents of the `lodash/fp/difference.js` file (not visible in the repo as it's constructed as part of the package release cycle AFAICT):
```js
var convert = require('./convert'),
func = convert('difference', require('../difference'));
func.placeholder = require('./placeholder');
module.exports = func;
```
Which results in the warning during compilation:
```
node_modules/lodash/fp/difference.js:2: WARNING - Failed to load module "../difference"
```
Now, my expectation is that I'm probably doing something wrong so here's a simple example file that fails and the `gulp` configuration that I'm using to kick off the whole process.
```js
import { difference } from 'lodash';
console.log(difference([1, 2, 3], [2]));
```
```js
const path = require('path');
const gulp = require('gulp');
const closureCompiler = require('google-closure-compiler').gulp();
gulp.task('bundle', function () {
return closureCompiler({
js: [
'node_modules/lodash/**/*.js',
'node_modules/lodash/package.json',
'src/**.js'
],
process_common_js_modules: true,
module_resolution: 'NODE',
dependency_mode: 'STRICT',
compilation_level: 'SIMPLE',
entry_point: 'src/main',
// warning_level: 'VERBOSE',
language_in: 'ECMASCRIPT6',
language_out: 'ECMASCRIPT5',
// generate_exports: true,
output_wrapper: '(function(){\n%output%\n}).call(this)',
js_output_file: 'bundle.min.js'
})
.src({ base: path.resolve(__dirname) })
.pipe(gulp.dest('./dist/js'));
});
```
Contributor guide
Assessment
This issue has not been assessed yet.