Typescript: tsc --watch is inconsistently reporting node_modules files as being outside rootDir

Created on 19 Oct 2017  路  6Comments  路  Source: microsoft/TypeScript




TypeScript Version: 2.6.0-rc

Code

With a directory layout like:

node_modules/
src/tsconfig.json
src/index.ts
package.json
import findCacheDir = require('find-cache-dir')

Expected behavior:

Compilation with no errors (other than findCacheDir not used if the option is enabled)

Actual behavior:

Intermittent error TS6059 whenever the file is edited. The error occasionally goes away or returns whenever a build is triggered by --watch.

If there are multiple files in the project almost all of them will produce errors for the things they are importing from node modules. But only sometimes 馃槙

error TS6059: File '.../node_modules/find-cache-dir/index.js' is not under 'rootDir' '.../src'. 'rootDir' is expected to contain all source files.
Bug Fixed

All 6 comments

This actually looks like a duplicate/side-effect of #19290

@Kovensky can u share your project?

@kovensky apart from the project, can you please let us know if node_modules folder is at root folder like c:/ or /user/username. That might help us investigate this further.
did you notice any pattern in edits that cause the errors to go away..
Doing tsc -w 鈥攅xtendedDiangostics would also give more info on what watches are being triggered to help us investigate it better

The change can be as simple as adding a newline to the end of the file. I can't seem to get it to _not_ happen anymore.

In this example, I started a build with -w --extendedDiagnostics, and after the initial build at 14:15:28 finished I added an extra empty line to webpack.config.ts:

14:15:28 - Compilation complete. Watching for file changes.


DirectoryWatcher recursive:: Added: PathInfo: /users/kovensky/src/work/webpack/src
FileWatcher:: Trigger: /Users/kovensky/src/work/webpack/src/webpack.config.ts 1 PathInfo: /Users/kovensky/src/work/webpack/src/webpack.config.ts
FileWatcher:: Elapsed: 1ms Trigger: /Users/kovensky/src/work/webpack/src/webpack.config.ts 1 PathInfo: /Users/kovensky/src/work/webpack/src/webpack.config.ts
14:15:30 - File change detected. Starting incremental compilation...


Synchronizing program
error TS6059: File '/Users/kovensky/src/work/node_modules/babel-plugin-transform-class-properties/lib/index.js' is not under 'rootDir' '/Users/kovensky/src/work/webpack/src'. 'rootDir' is expected to contain all source files.

(followed by 20 or so similar errors with different node modules)

The output directory structure is also strange. With --outDir dist, the initial compilation is as expected (e.g. dist/webpack.config.js), but the buggy incremental build puts the output in dist/webpack/src, and only the incrementally built files are in there.

@Kovensky Thank you for the information.. I did some experimentation based on error you are getting and directory structure you mentioned and i have found a repro for this (ab67477). I am working on the fix

@Kovensky can you give tomorrow's typescript@next another try.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

weswigham picture weswigham  路  3Comments

blendsdk picture blendsdk  路  3Comments

siddjain picture siddjain  路  3Comments

jbondc picture jbondc  路  3Comments

seanzer picture seanzer  路  3Comments