Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage with rollup-plugin-alias -- put alias first and add .ts extension #65

Closed
lijialiang opened this issue Mar 13, 2018 · 5 comments
Closed
Labels
kind: support Asking for support with something or a specific use case problem: plugin order The plugin order in this issue seems incompatible. See the "Compatibility" section in the README scope: integration Related to an integration, not necessarily to core (but could influence core)

Comments

@lijialiang
Copy link

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

@ezolenko ezolenko self-assigned this Mar 20, 2018
@ezolenko
Copy link
Owner

ezolenko commented Mar 20, 2018

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/

@ezolenko ezolenko removed their assignment Apr 27, 2018
@ezolenko
Copy link
Owner

Likely plugin order thing

@viT-1
Copy link

viT-1 commented Aug 22, 2019

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

@alsotang
Copy link

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

@agilgur5 agilgur5 changed the title using it with rollup-plugin-alias usage with rollup-plugin-alias May 22, 2022
@agilgur5 agilgur5 added kind: support Asking for support with something or a specific use case problem: plugin order The plugin order in this issue seems incompatible. See the "Compatibility" section in the README labels May 22, 2022
@agilgur5 agilgur5 changed the title usage with rollup-plugin-alias usage with rollup-plugin-alias -- put alias first and add .ts extension May 22, 2022
@agilgur5 agilgur5 added the scope: integration Related to an integration, not necessarily to core (but could influence core) label May 22, 2022
@agilgur5
Copy link
Collaborator

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

Looking at the original config, I believe it's because it didn't set a .ts extension in the alias resolve options. Notably, #125 (comment) sets it and got it to work.
The current version of alias has different options, but a similar configuration is probably needed for it.


....That being said, once you fix the extensions, you may end up missing the aliases in your declaration files, i.e. #125 .
Per my comment there, please see #201 for further discussion, workarounds, etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case problem: plugin order The plugin order in this issue seems incompatible. See the "Compatibility" section in the README scope: integration Related to an integration, not necessarily to core (but could influence core)
Projects
None yet
Development

No branches or pull requests

5 participants