question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "Unexpected token <" error since using SystemJS

See original GitHub issue

Hey 👋


Operating System : macOS Sierra Node.js version : v8.1.2 npm version: 5.0.3


I have switched my loader from RequireJS to SystemJS this morning. To make the change I have install a new aurelia application and I have compare package.json, tasks/*, aurelia.json and index.html files and made the change needed.

The application bundle correctly, but when I try to launch it in the browser I have the error Unexpected token < at random place.

Note that everything was working fine before making the change.

<center>screen shot 2017-06-21 at 11 48 03</center>

If we take a look to the vendor-bundle.js file at the line 11707 we arrive on the loadModule function.

DefaultLoader.prototype.loadModule = function (id) {
  var _this3 = this;

  return System.normalize(id).then(function (newId) {
    var existing = _this3.moduleRegistry[newId];
    if (existing !== undefined) {
      return Promise.resolve(existing);
    }

    return System.import(newId).then(function (m) {                  // 11707
      _this3.moduleRegistry[newId] = m;
      return ensureOriginOnExports(m, newId);
    });
  });
};

The package @fivb/sdk is a TypeScript package compiled and transpiled to ES5 in different module formats (amd, commonjs, es2015, umd).

In my aurelia.json, I load it as an amd package.

{
  "name": "@fivb/sdk",
  "path": "../node_modules/@fivb/sdk/dist/amd",
  "main": "index"
},

Since SystemJS should handle commonjs as well, I have tried to use this version.

{
  "name": "@fivb/sdk",
  "path": "../node_modules/@fivb/sdk/dist/commonjs",
  "main": "index"
},

Now the error Unexpected token < is gone for @fivb/sdk but happen for axios.

{
  "name": "axios",
  "path": "../node_modules/axios/dist",
  "main": "axios"
},
screen shot 2017-06-21 at 12 16 07

The line 3388 is the definition of SystemJS.

/*
 * SystemJS v0.20.14 Dev
 */
!function(){"use strict" ... }

Note that axios is used by @fivb/sdk.

Here’s my current aurelia.json : https://gist.github.com/RomainLanz/cf6738932e73379dc62c994006e1fb18

I can give access to this application repository and to @fivb/sdk if needed.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
simonfoxcommented, Jun 23, 2017

OK I’ve got to the bottom of this. amodro wraps anonymous amd modules on write - see here.

The two packages causing problems here have source map links in the dist script e.g. the last line of axios is

//# sourceMappingURL=axios.map

Combine those two factors and the result is a bundle that contains

//# sourceMappingURL=axios.map;define('axios', ['axios/axios'], function (main) { return main; });

For better or worse RequireJS handles that case.

@JeroenVinke would you like a PR to just add a newline before the wrapper is appended? Or is there some other consideration I have missed?

0reactions
RomainLanzcommented, Jul 24, 2017

Side note : It works fine with the Webpack bundler

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Error: (SystemJS) Unexpected token < SyntaxError ...
I am getting the below error when importing it in my app.module.ts. "(SystemJS) Unexpected token < SyntaxError: Unexpected token < at eval ...
Read more >
uncaught (in promise) syntaxerror: unexpected token - You.com
I am getting two errors in my React client: App.js:11 GET http://localhost:3000/acceptStockTicker 500 (Internal Server Error); VM347:1 Uncaught (in promise) ...
Read more >
missing file lib/angular2-modal/plugins/bootstrap.js
... after compiling when I try to launch the application I am getting this error in browser console, Error: SyntaxError: Unexpected token <...
Read more >
Unexpected token '<' SystemJs ( 0.21.5v )-angular.js
This is because node modules were not loaded properly. I fixed this issue by importing all the modules in a single system.config.ts. Also...
Read more >
systemjs/systemjs - Gitter
I will often get errors similar to this: system.js:4 Uncaught (in promise) Error: (SystemJS) Unexpected token <(…) There is a stacktrace, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found