Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Not working with [email protected] #306

Open
kluevandrew opened this issue Dec 26, 2017 · 0 comments
Open

Not working with [email protected] #306

kluevandrew opened this issue Dec 26, 2017 · 0 comments

Comments

@kluevandrew
Copy link

Bug, feature request, or proposal:

After upgrade and some breaking changes in @angular/compiler-cli library can't be build with rollup in AoT mode

What is the expected behavior?

Library works in AoT mode

What is the current behavior?

Errors like

[13:25:25] 'rollup' errored after 6.59 s
[13:25:25] Error: Could not resolve './calendar-body' from aot/tmp/node_modules/md2/datepicker/calendar-body.ngfactory.js
    at error (/home/andrew/www/riotgames/live/dashboard/node_modules/rollup/dist/rollup.js:185:14)
    at then.resolvedId (/home/andrew/www/riotgames/live/dashboard/node_modules/rollup/dist/rollup.js:18244:8)
    at <anonymous>

Because paths in compiled files like ./aot/tmp/node_modules/md2/datepicker/calendar-body.ngfactory.js
are relative ex. import * as i3 from "./calendar-body";

My tsconfig.json is:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es2015", "dom"],
    "removeComments": false,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "allowSyntheticDefaultImports": true,
    "outDir": "./aot/tmp",
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "include": [
    "./src/app/**/*",
    "./node_modules/@types/**/*"
  ],
  "files": [
    "./src/app/app.module.ts",
    "./src/app/boot.aot.ts",
    "./src/app/boot.development.ts"
  ],
  "exclude": [
    "src/**/*.spec.ts",
  ],
  "angularCompilerOptions": {
    "debug": true,
    "genDir": "./aot/tmp",
    "skipMetadataEmit" : true
  }
}

What are the steps to reproduce?

  1. Create any [email protected] app
  2. Compile it with ngc
  3. Try to rollup your app

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, MD2, OS, browsers are affected?

[email protected]
[email protected]
[email protected]

My workaround

  const fs = require('fs');
  const path = require('path');

  function ensureJsExt(fn) {
      return /\.js$/.test(fn) ? fn : fn + '.js';
  }

  function md2resolveId(importee, from) {
    if (from && (/^\.\/.*/.test(importee) || /^\.\.\/.*/.test(importee))) {
      var match = from.match(/^.*(node_modules\/md2\/.*$)/);
      if (match) {
        var dirTmp = path.dirname(from);
        var dirReal = path.dirname(match[1]);
        var pathTmp = ensureJsExt(dirTmp + '/' + importee);
        var pathReal = ensureJsExt('./' + dirReal + '/' + importee);

        return fs.realpathSync(fs.existsSync(pathTmp) ? pathTmp : pathReal);
      }
    }

    return false;
  }

 rollup({
  plugins: [
            ...
            {resolveId: resolveId}
           ...
  ]
})
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant