gulp-typescript icon indicating copy to clipboard operation
gulp-typescript copied to clipboard

paths work incorrect

Open keyiis opened this issue 3 years ago • 4 comments

Gulp-typescript encountered an error when I upgraded typescript from 3.9 to 4.5 env: [email protected] [email protected] tsconfig:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        // "allowSyntheticDefaultImports": true,
        // "noUnusedLocals": true,
        "removeComments": true,
        "skipLibCheck":true,
        "sourceMap": true,
        "declaration": false,
        "pretty": true,
        // "strictNullChecks": true,
        "lib": [
            "es2015",
            "es2016",
            "es2017"
        ],
        "baseUrl": ".",
        "paths": {
            "@common/*": [ "src/common/*" ]
        }
    }
}

directory structure:

D:/edge
    src
        common/*
        projects/core/*
    tsconfig.json

gulp script

let tsProject = ts.createProject("tsconfig.json");
gulp.src([`D:/edge/src/projects/core/**/*.ts`], { base: `D:/edge/src/projects/core` })
        .pipe(cached('compileProject'))    
        .pipe(tsProject())
        .pipe(gulp.dest(DIST_PATH));

error:

D:/edge/src/common/entitys/index.ts(1,15): error TS6059: File 'D:/edge/src/common/entitys/Job.ts' is not under 'rootDir' 'src\projects\core'. 'rootDir' is expected to contain all source files.
D:/edge/src/common/entitys/Job.ts(2,28): error TS6059: File 'D:/edge/src/common/config.ts' is not under 'rootDir' 'src\projects\core'. 'rootDir' is expected to contain all source files.
  The file is in the program because:
    Imported via '@common/config' from file 'D:/edge/src/common/entitys/Job.ts'
    Imported via './config' from file 'D:/edge/src/common/dbUtil.ts'

when i downgrade Gulp-typescript to 3.9,all work well,when I searched typescript's help manual, I found below https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#paths-without-baseurl But I removed baseurl, and the error still exists.

keyiis avatar Dec 01 '21 09:12 keyiis

just ran into this as well. Works with typescript ~4.2.0 but breaks with ~4.3.0

bmayen avatar Dec 01 '21 15:12 bmayen

@bmayen I just did the test, just like you.

keyiis avatar Dec 02 '21 01:12 keyiis

Contrary to tsc, we must always set rootDir in gulp-typescript to work with the virtual file system in gulp. It's inferred from the input stream (e.g. from gulp.src) but if it's inferred incorrectly you'll need to specify it yourself. Can you try to add that option?

ivogabe avatar Dec 14 '21 21:12 ivogabe

Contrary to tsc, we must always set rootDir in gulp-typescript to work with the virtual file system in gulp. It's inferred from the input stream (e.g. from gulp.src) but if it's inferred incorrectly you'll need to specify it yourself. Can you try to add that option?

I face the same issue @ivogabe I upgraded the typescript version from 4.1 to 4.5. as you suggested I specified the input stream but still not working. please help us

akaDPR avatar Dec 29 '21 14:12 akaDPR