3

I can't seem to figure out how to import JSNLog into my ES6 (babel) based Aurelia project. I've tried:

import 'jsnlog';            // JL is undefined
import JL from 'jsnlog';    // JL is {}
import {JL} from 'jsnlog';  // JL is undefined

If it matters I've learned that the jsnlog.js file is generated from typescript source.

David Lynch
  • 1,716
  • 15
  • 15
  • You could try to compile jsnlog from typescript to ES6, then let babel do the rest. – Bergi Feb 28 '16 at 15:20
  • I'd prefer to consume the JSNLog distribution directly (if possible), without needing a custom build step for a dependency. – David Lynch Feb 28 '16 at 15:30
  • In that case the first one should work - the lib defines a global. What code does babel create for this, what module loader/bundler are you using, how do you inject the distributed library in your module repository? – Bergi Feb 28 '16 at 15:31
  • The JL variable is undefined when I use #1. The jsnlog.js file is a "format cjs" style CommonJS module that was directly generated by TypeScript. – David Lynch Feb 28 '16 at 16:03
  • How did you install `jsnlog`? What version? which version of Babel? For me, `import { JL } from 'jsnlog'` works as expected after `npm install jsnlog`. I am using `babel-cli@6.5.1` and I installed `jsnlog@2.17.0`. – joews Feb 28 '16 at 16:38
  • This is client\browser code so I installed with `jspm install npm:jsnlog`. – David Lynch Feb 28 '16 at 16:49

3 Answers3

2

I am the author of JSNLog.

Just added info to the jsnlog.com site about using ES6 import to import JSNLog into an ES6 NodeJs application: http://jsnlog.com/Documentation/HowTo/LoadingJsFile#es6 (using Babel as the transpiler).

This uses:

import {JL} from 'jsnlog';
user1147862
  • 4,096
  • 8
  • 36
  • 53
  • My issue is using jsnlog in a client application. Tracking the issue here: https://github.com/mperdeck/jsnlog.js/issues/24 – David Lynch Mar 15 '16 at 14:28
2

The author has fixed this issue with the v2.17.1 release.

David Lynch
  • 1,716
  • 15
  • 15
1

According to this line from the source code the following

import {JL} from 'jsnlog';

should work. At least, it works for me.

If it doesn't, check out your SystemJS setup. The issue will be somewhere there.

just-boris
  • 9,468
  • 5
  • 48
  • 84