falsandtru / pjax-api

The advanced PJAX superior to SPA.
https://falsandtru.github.io/pjax-api/
Apache License 2.0
318 stars 28 forks source link

Cannot find module './type' #28

Closed Flobin closed 7 years ago

Flobin commented 7 years ago

I thought I’d give Pjax another try. I installed it with npm install pjax-api --save.

I am including it like this:

var Pjax = require('pjax-api').Pjax;

function DOMContentLoaded() {
  new Pjax({
    areas: [
      // try to use the first query.
      'main, .content',
      // fallback.
      'body'
    ]
  });
}

And setting it up through Gulp like this:

gulp.task('site-scripts', function () {
  var b = browserify({
    entries: ['src/scripts/main.js'],
    debug: true
  });

  return b.bundle()
    .pipe(source('main.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
        // Add transformation tasks to the pipeline here.
        .pipe(uglify())
        .on('error', gutil.log)
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('build/js/'));
});

However, I'm getting this error:

events.js:160 throw er; // Unhandled 'error' event ^

Error: Cannot find module './type' from '/Users/robin/work/2017-01-02_DAVL_website/kirby/assets/node_modules/pjax-api/dist' at /Users/robin/work/2017-01-02_DAVL_website/kirby/assets/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21 at load (/Users/robin/work/2017-01-02_DAVL_website/kirby/assets/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43) at onex (/Users/robin/work/2017-01-02_DAVL_website/kirby/assets/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31) at /Users/robin/work/2017-01-02_DAVL_website/kirby/assets/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47 at FSReqWrap.oncomplete (fs.js:117:15)

Is there something missing, or could this be a Browserify issue?

falsandtru commented 7 years ago

You can avoid bundling external modules using opts.bundleExternal or some methods. See https://github.com/substack/node-browserify

Flobin commented 7 years ago

This solved the issue. Thank you!