systemjs: Error resolving .js files from filesystem

I have the following build script:

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

const pkg = require('./package.json');
const deps = pkg.dependencies;

function getPaths(){
  return Object.map(deps, function(k,v){
      return require.resolve(k);
  });
}


let builder = new Builder(__dirname, {
  paths: getPaths()
});

let src = path.resolve(__dirname + '/browser-polyfills/dest/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);
});

I get this error:

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

I confirmed that require.resolve() will always return a .js file, even for ascii-table, and this file exists on my filesystem. It seems clear that SystemJS should be looking for:

/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/ascii-table/ascii-table.js

but instead, SystemJS is erroneously looking for:

/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman/node_modules/ascii-table/ascii-table

It’s looking for a file without the .js extension…

this is such a fundamental problem (I have seen the same with RequireJS), why does this happen?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

@ORESoftware I think you’re just after main: "ascii-table.js", or just use something like:

{
  map: {
    'ascii-table': 'node_modules/ascii-table.js' // (node_modules may or may not be needed depending on your baseURL config)
  }
}

For this error, it is likely due to ascii-table does not have package.json/main specified. https://github.com/unional/domture#usage

Try to do the following:

 packages: {
        // This is need for some packages due to https://github.com/systemjs/systemjs/issues/1603
        'make-error': {
          main: 'index'
        }
      }

Likely a duplication of https://github.com/systemjs/systemjs/issues/1603

In the meantime, I am going to go cry for awhile LOL