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

Monorepo: watch mode results in Error: Could not find source file #214

Closed
jrburke opened this issue Mar 11, 2020 · 9 comments · Fixed by #332
Closed

Monorepo: watch mode results in Error: Could not find source file #214

jrburke opened this issue Mar 11, 2020 · 9 comments · Fixed by #332
Labels
kind: bug Something isn't working properly problem: plugin order The plugin order in this issue seems incompatible. See the "Compatibility" section in the README scope: watch mode Related to Rollup's watch mode solution: workaround available There is a workaround available for this issue topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc) topic: TS Compiler API Docs Related to the severely lacking TS Compiler API Docs

Comments

@jrburke
Copy link

jrburke commented Mar 11, 2020

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

@ezolenko
Copy link
Owner

Might be related to #188

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

@ezolenko ezolenko added the kind: bug Something isn't working properly label Mar 11, 2020
@rmedaer
Copy link

rmedaer commented Apr 12, 2020

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.

@xiaoyuze88
Copy link

xiaoyuze88 commented Oct 29, 2021

I have a similar issue currently, using lerna and a (plugin rpt2) Error: Could not find source file showed up.

I fix this by simply change the order of the plugins from:

[
  typescript(),
  resolve(),
  commonjs(),
]

to

[
  resolve(),
  commonjs(),
  typescript(),
]

Maybe you can have a shot.

@daief
Copy link

daief commented Jan 8, 2022

[... removed for brevity/readability...]

I fix this by simply change the order of the plugins from:

[... removed for brevity/readability...]

This solved my same problem.

绝了。

@toakleaf
Copy link

toakleaf commented Mar 1, 2022

Reordering didn't help me much. Had to go with the check: false method to get hot reloading working again.

For more context, I'm using turborepo monorepo, and while the initial running of the dev server finds my typescript files in the monorepo packages/ dir, all subsequent hot reloads fail to find the dependencies.

@agilgur5 agilgur5 changed the title Monorepo: rollup -w with rpt2 results in (plugin rpt2) Error: Could not find source file Monorepo: rollup -w results in Error: Could not find source file Apr 28, 2022
@agilgur5 agilgur5 added solution: workaround available There is a workaround available for this issue topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc) labels Apr 28, 2022
@yuuk
Copy link

yuuk commented May 10, 2022

It's occasionally occur the error in my case, when i modify rollup.config.js and save, it compiled successfully.

@agilgur5 agilgur5 changed the title Monorepo: rollup -w results in Error: Could not find source file Monorepo: watch mode results in Error: Could not find source file Jun 9, 2022
@agilgur5 agilgur5 added the scope: watch mode Related to Rollup's watch mode label Jun 9, 2022
@agilgur5 agilgur5 added the problem: plugin order The plugin order in this issue seems incompatible. See the "Compatibility" section in the README label Jun 22, 2022
@agilgur5
Copy link
Collaborator

This seems to have been fixed by #332 which was released in 0.32.0.

I tested the reproduction with 0.31, which had the same error, then upgraded to 0.32+ and the error went away and it was compiling successfully during all changes in watch mode.
Thanks @jrburke for the repro with step-by-step directions!

As such, closing this as fixed. Please upgrade to 0.32+ if you're experiencing this error.

@agilgur5 agilgur5 added the topic: TS Compiler API Docs Related to the severely lacking TS Compiler API Docs label Jun 28, 2022
@aaacafe786

This comment was marked as off-topic.

@agilgur5

This comment was marked as resolved.

Repository owner locked as resolved and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: bug Something isn't working properly problem: plugin order The plugin order in this issue seems incompatible. See the "Compatibility" section in the README scope: watch mode Related to Rollup's watch mode solution: workaround available There is a workaround available for this issue topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc) topic: TS Compiler API Docs Related to the severely lacking TS Compiler API Docs
Projects
None yet
9 participants