2

An NPM module offer some extensions in a folder :

gojs
   extensions
       DebugInspector.js
   release
   packages.json

Each extensions contain one class without any (es2015) export syntax like :

function Inspector(...) {

}

Inspector.prototype.inspectObject = function(obj) {

}

How to use it with webpack ? I tried a simple export like :

import 'gojs/extensions/DebugInspector.js';

The file is correctly imported and compiled but I can't create a new instance of DebugInspector, the Inspector function is undefined. It's probably, surely a duplicate question but I can't find any example like this code (or I dont use the correct words to search).

This example is not related to the Mike's example because the imported file doesn't support any AMD mechanism.

8
  • You really have to export something in order to import and use it elsewhere. I would suggest forking the repository and creating your own NPM module with an added export statement. Perhaps you can even get the original maintainer to merge it into their code base. Commented Jul 3, 2017 at 13:53
  • Humm it was my anxiety. And with a simple require ? Same sound ? Commented Jul 3, 2017 at 14:06
  • Same I'm afraid. Modules don't actually exist yet in JavaScript. When you use JS modules today you're essentially wrapping your code in functions provided by your build system (node, webpack, requirejs etc.). These functions depend on the exports object being filled. If it's not filled, they happily continue and not expose anything. Commented Jul 3, 2017 at 14:55
  • Possible duplicate of Importing "regular" javascript packages installed with npm in Webpack Commented Jul 3, 2017 at 15:33
  • 1
    @MikeMcCaughan, I can but I dont want the main principe of NPM is to maintain module to the latest version. I'm very suprise Webpack can't import a file as "global" like a simple "script" tag without any use of AMD/UMD/etc. or ES2015 mechanism. Commented Jul 4, 2017 at 7:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.