Rollup-plugin-typescript2: using it with rollup-plugin-alias

Created on 13 Mar 2018  ·  4Comments  ·  Source: ezolenko/rollup-plugin-typescript2

Failed to find the modules

Environment

node v8.9.1

Versions

  • typescript: 2.7.2
  • rollup: 0.56.5
  • rollup-plugin-typescript2: 0.12.0

rollup.config.js

const path = require('path');

import typescript from 'rollup-plugin-typescript2';
import alias from 'rollup-plugin-alias';

export default {
    input: './src/index.ts',
    output: {
        file: 'build.js',
        format: 'umd',
        name: 'build',
    },
    plugins: [
        typescript( ),
        alias( {
            core: path.resolve( __dirname, './src/core' ),
        } ),
    ],
};

tsconfig.json

{
    "compilerOptions": {
        "target": "es2015"
    }
}

package.json

{
  "name": "rollup-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "rollup -c ./rollup.config.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "rollup": "^0.56.5",
    "rollup-plugin-alias": "^1.4.0",
    "rollup-plugin-typescript2": "^0.12.0",
    "typescript": "^2.7.2"
  }
}

TS files

// ./src/index.ts
import A from 'core/a';
export { A };
// ./src/core/a.ts
export default function  () {
    const x = 12;
    console.log( x );
};

Error

rollup-demo/src/index.ts(1,15): semantic error TS2307 Cannot find module 'core/a'.

Problem

If use rollup-plugin-alias alone, it will work.

but with rollup-plugin-typescript2 used together, it can't find the module

Most helpful comment

I tried this configuration. Set alias in front of typescript2 not helped =(

All 4 comments

Did you try placing alias() in front of typescript()?

Can you work around this by using baseUrl in tsconfig?

See more info here:
https://decembersoft.com/posts/say-goodbye-to-relative-paths-in-typescript-imports/

Likely plugin order thing

I tried this configuration. Set alias in front of typescript2 not helped =(

I met the same problem when using @rollup/plugin-alias and @rollup/plugin-typescript.
Moving alias bebind typescript solve the problem.

Was this page helpful?
0 / 5 - 0 ratings