Rollup-plugin-typescript2: Monorepo: rollup -w with rpt2 results in (plugin rpt2) Error: Could not find source file

Created on 11 Mar 2020  ·  2Comments  ·  Source: ezolenko/rollup-plugin-typescript2

What happens and why it is wrong

A normal one-time build works fine. However, when using rollup -w, rpt2 seems to have trouble finding source files if I edit one of the deeper module dependencies in one of the other packages.

This is with a Lerna monorepo setting up symlinks to the in-repo dependencies.

Test repo: https://github.com/jrburke/jr-monorepo-rpt2

I do not want to use preserveSymlinks because in my real project, it results in duplicates of modules in the final built project, since multiple packages in the repo share common dependencies. I have tried a version using preserveSymlinks, and so as a last resort I could configure a dev setup that uses preserveSymlinks, but standalone/first time builds work without it, and I would like to keep the watch setup the same as the normal builds.

Environment

Details to reproduce in the above example repo.

Versions

  • typescript: 3.8.3
  • rollup: 1.32.1
  • rollup-plugin-typescript2: 0.26.0

rollup.config.js

import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/jr-player.js',
    format: 'iife',
    name: 'jrPlayer',
    exports: 'named'
  },
  watch: {
    include: ['src/**', '../jr-lib/src/**', '../jr-auth/src/**']
  },
  plugins: [
    typescript({
      include: ['src/**/*.ts+(|x)', '../jr-lib/**/*.ts+(|x)', '../jr-auth/**/*.ts+(|x)'],
      verbosity: 3
    }),
    resolve(),
    commonjs()
  ]
};

tsconfig.json

Top level tsconfig.json:

{
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "es2015",
    "lib": [
      "es2015",
      "es2016",
      "es2017",
      "dom"
    ],
    "strict": true,
    "sourceMap": true,
    "declaration": true,
    "allowSyntheticDefaultImports": true,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "removeComments": true,
    "resolveJsonModule": true,
    "skipLibCheck": true
  }
}

packages/jr-player/tsconfig.json:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "target": "es5",
    "declarationDir": "lib",
    "outDir": "lib"
  },
  "include": ["."]
}

package.json

I don't think it is relevant, but it is in the test repo.

plugin output with verbosity 3

Attached, but also in test repo at verbose-error.txt:

verbose-error.txt

bug

All 2 comments

Might be related to #188

Another workaround is to disable typechecking with check: false, of course that removes majority of functionality...

I have the issue combining rollup-plugin-typescript2 and rollup-plugin-postcss. When I import a _css_ file (e.g. import * as style from ./mystyle.css) and I enable _watch_ flag, it gives me the same error.

I'll try debug a little bit more, but indeed check: false fix the issue.

Was this page helpful?
0 / 5 - 0 ratings