-1

The rollup documentation has the following example of importing the util.ajax function:

import { ajax } from 'utils';

Does node expose an ES6 module containing utils via the module key on package.json and is this the general pattern used by NodeJS?

Update for those wondering what the purpose of the question is - If this is the case then rollupjs can tree shake node modules directly without having to transpile them to ES6 modules first.

Ole
  • 41,793
  • 59
  • 191
  • 359
  • What are you trying to do? It is unclear in your question... – Badacadabra May 16 '17 at 20:34
  • a little bit of research goes a long way. There are literally *hundreds* of articles that cover ES6 `import`. The [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) shows the syntax you are asking about. – Claies May 16 '17 at 20:39
  • 1
    No. You still need to transpile the import to a `require()` call, which includes the `utils` commonjs module. – Bergi May 16 '17 at 20:44
  • Cool - Thanks @Bergi - In this case targeting doing the reverse - transpiling the `utils` module to ES6 such that tree shaking can be performed - turns out there's a rollupjs plugin (rollup-plugin-commonjs) that supports this. – Ole May 16 '17 at 21:00

1 Answers1

1

It's just a fictional example of a module that you could import. It's not a built-in module like Node's util.

Rich Harris
  • 28,091
  • 3
  • 84
  • 99