Rollup: JavaScript API, paths not working

Created on 26 Jan 2017  Â·  2Comments  Â·  Source: rollup/rollup

I'm writing an Ionic2 application that needs to import a module from a .js file.
directory structure:

scripts
-rollup.config.js
src
-common
--lib
---SafeLogger.ts

Safelogger.ts:
import * as Telemetry from 'aria'; //do stuff...
My rollup.config.js file:

var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
var globals = require('rollup-plugin-node-globals');
var builtins = require('rollup-plugin-node-builtins');
var json = require('rollup-plugin-json');

// https://github.com/rollup/rollup/wiki/JavaScript-API

var rollupConfig = {
  /**
   * entry: The bundle's starting point. This file will
   * be included, along with the minimum necessary code
   * from its dependencies
   */
  entry: process.env.IONIC_APP_ENTRY_POINT,

  /**
   * sourceMap: If true, a separate sourcemap file will
   * be created.
   */
  sourceMap: process.env.IONIC_GENERATE_SOURCE_MAP ? true : false,

  /**
   * format: The format of the generated bundle
   */
  format: 'iife',

  /**
   * dest: the output filename for the bundle in the buildDir
   */
  dest: process.env.IONIC_OUTPUT_JS_FILE_NAME,

  /**
   * plugins: Array of plugin objects, or a single plugin object.
   * See https://github.com/rollup/rollup/wiki/Plugins for more info.
   */
  plugins: [
    builtins(),
    commonjs(),
    nodeResolve({
      module: true,
      jsnext: true,
      main: true,
      browser: true,
      extensions: ['.js']
    }),
    globals(),
    json()
  ],
  paths: {
    aria: 'src/common/lib/aria-web-telemetry-2.7.1.min.js'
  }
};



module.exports = rollupConfig;

this is the error I am getting:

[19:34:12]  rollup failed: Could not resolve 'aria' from
            C:\Users\golear\Source\Repos\MobileShoppingAssist\src\common\tracking\SafeLogger.ts
[19:34:12]  ionic-app-script task: "build"

Rollup version 0.36.4

Am I using paths incorrectly? I can't figure out what I'm doing wrong.

t² 📚 documentation x¹ ⋅ abandoned

Most helpful comment

In short:
use rollup-plugin-alias

In long:
It took me a bit to figure out the purpose for paths. Below are my observations

for future readers, the paths config option can be found here.

It seems to be intended for external dependencies. If you see in rollup's codebase, they use it like the following:

// rollup.config.cli.js

external: [... 'rollup', ....]
, paths: {
  rollup: '../dist/rollup.js'
}

and the before/after shows

// bin/src/runRollup.js

import * as rollup from 'rollup';
// bin/rollup

var rollup = require('../dist/rollup.js');

Looking at the wiki description, we have to read it literally to understand:

these paths will be used in the generated bundle instead of the module ID, allowing you to (for example) load dependencies from a CDN

Where I emphasize "in the generated bundle" instead of "when generating a bundle". Up for interpretation I suppose, but my tests show this seems to be the intent.

All 2 comments

In short:
use rollup-plugin-alias

In long:
It took me a bit to figure out the purpose for paths. Below are my observations

for future readers, the paths config option can be found here.

It seems to be intended for external dependencies. If you see in rollup's codebase, they use it like the following:

// rollup.config.cli.js

external: [... 'rollup', ....]
, paths: {
  rollup: '../dist/rollup.js'
}

and the before/after shows

// bin/src/runRollup.js

import * as rollup from 'rollup';
// bin/rollup

var rollup = require('../dist/rollup.js');

Looking at the wiki description, we have to read it literally to understand:

these paths will be used in the generated bundle instead of the module ID, allowing you to (for example) load dependencies from a CDN

Where I emphasize "in the generated bundle" instead of "when generating a bundle". Up for interpretation I suppose, but my tests show this seems to be the intent.

Closing as this has been inactive for a while and newer relevant issues can track these concerns. Happy to continue discussion as well here too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Havunen picture Havunen  Â·  3Comments

Conduitry picture Conduitry  Â·  3Comments

azdavis picture azdavis  Â·  3Comments

otakustay picture otakustay  Â·  3Comments

nanomosfet picture nanomosfet  Â·  3Comments