systemjs / builder

SystemJS build tool
MIT License
465 stars 122 forks source link

Support for bundling assert (Node.js core) and async (NPM) modules #796

Closed ORESoftware closed 7 years ago

ORESoftware commented 7 years ago

I have this script:

let path = require('path');
let Builder = require('systemjs-builder');

let builder = new Builder(__dirname, {

  paths: {
    assert: require.resolve('assert'),
    async: require.resolve('async')
  }

});

let src = path.resolve(__dirname + '/browser-polyfills/systemjs/all-core-and-npm.js');
let dest = path.resolve(__dirname + '/dist/outfile.js');

builder
.bundle(src, dest )
.then(function() {
  console.log('Build complete');
})
.catch(function(err) {
  console.log('Build error');
  console.log(err);
});

it's pointing to a node.js file in my project that simply has 2 lines like so:

require('assert');
require('async');

what I am looking to do is bundle the core assert module and the async NPM module into a SystemJS build for the front-end.

However when running the script, I get this output:

Build error
{ Error on fetch for assert at file:///Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/assert
        Loading browser-polyfills/systemjs/all-core-and-npm.js
        Error: ENOENT: no such file or directory, open '/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/assert'
    at Error (native)
  originalErr: 
   { Error: ENOENT: no such file or directory, open '/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/assert'
       at Error (native)
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/assert' } }

is there any way to accomplish want I want to do? Totally stuck. Thanks.

ORESoftware commented 7 years ago

I realized what was happening => require.resolve('assert') does not yield an absolute path, it actually doesn't even yield a path at all (same for any core module), I filed a ticket with Node.js about this, since that seems bad. Closing, thanks.

In other words:

require.resolve(<core-module>) => major nodejs fail