Module not found but still works
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- build-system, tooling
Research direction
Start by reproducing the generated bundles with the posted gulp compilation script, Browserify, factor-bundle, and the two page entries. Inspect the generated module mapping around the jquery require and compare the homepage and product bundles; done means the homepage no longer reports the missing module while both pages continue to work.
Written by the indexing model from the issue text.
Description
Hi,
I've got a strange behavior with my scripts.
I have 2 JS files : home.js and product.js for the concerned page.
Both require the common.js file, it works fine on the product page but on the homepage I have this error :
"Uncaught Error: Cannot find module '51'"
More about this error :
var _jquery = require('jquery');
var _jquery2 = _interopRequireDefault(_jquery);
var _common = require('../common/common.js');
var _common2 = _interopRequireDefault(_common);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {'default':obj}; }
(0, _jquery2['default'])(function () {
_common2['default'].init();
});
},{"../common/common.js":88,"jquery":51}]},{},[89]);
But, the JS still works. When I look further on the console, it's apparently the first module I have imported in the home.js script (jquery).
Here is my compilation script:
'use strict';
const __DEV__ = process.argv.indexOf('--dev') > -1;
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const browserify = require('browserify');
const babelify = require('babelify');
const watchify = require('watchify');
const replace = require('gulp-replace');
const gutil = require('gulp-util');
module.exports = function(config, prefix) {
return function() {
const folders = fs.readdirSync('./src/pages');
const files = folders.reduce((acc, folder) => {
if (folder != 'common') {
acc.entries.push(path.join(__dirname, `../src/pages/${folder}/${folder}.js`));
acc.outputs.push(path.join(__dirname, `../dist/assets/scripts/${folder}.bundle.js`));
}
return acc;
}, { entries: [], outputs: [] });
const stream = browserify({
entries: files.entries,
cache: {},
packageCache: {},
})
.transform('babelify', { presets: ['es2015'] })
.plugin(watchify)
.plugin('factor-bundle', {
outputs: files.outputs,
})
stream.on('update', bundle);
return bundle();
function bundle() {
return stream
.bundle()
.on('error', e => {
gutil.log(gutil.colors.red('Bundle error:', e.message));
})
.pipe(fs.createWriteStream(`${config.distOutputPath}/common.bundle.js`))
.on('finish', () => {
return gulp.src(config.distPath)
.pipe(replace(/var-/g, prefix + '-'))
.pipe(replace(/\.default(?=\.|\;|\)|\,|\(|\s)/g,"['default']"))
.pipe(replace(/\{ default: obj }/g,"{'default':obj}"))
.pipe(gulp.dest(config.distOutputPath))
.pipe(notify('Scripts task end'));
});
}
};
}
I work on Windows 7 with Node.js v4.2.
- Dominant language
- JavaScript
- Stars
- 397
- Forks
- 24
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from browserify/factor-bundle
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
browserify/factor-bundle#95 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
browserify/factor-bundle#94 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
browserify/factor-bundle#92 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
browserify/factor-bundle#83 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
browserify/factor-bundle#82 · 3 reactions ·
All issues in browserify/factor-bundle
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mksglu/context-mode#1200 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
neondatabase/website#5944 ·
-
module: core
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
bigbluebutton/bigbluebutton#25849 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jaegertracing/jaeger-ui#4506 ·