question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
rmedaercommented, Jun 22, 2022

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.

4reactions
xiaoyuze88commented, Apr 28, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest: Could not find source file error - DEV Community ‍ ‍
Occasionally I've been seeing the following error when running my Jest test suite. The source files always exist in the right location -...
Read more >
TypeScript project with references - Stack Overflow
Found this when searching for "typescript references has not been built from source file". My mistake was that I was running tsc -p ......
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
Setting up a mono repo from scratch. We will be using TypeScript, Yarn workspaces, Lerna, and Jest. The release of the packages will...
Read more >
The Case for Monorepos: A sane Workspace Setup (Part 2)
Learn how to setup dev tooling in a monorepo, run tasks efficiently, release multiple packages and overcome common DevOps challenges.
Read more >
rollup.js
This will not throw an error if one of the entry point files is not available. ... Import everything from the source module...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found