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

Error: gulp-typescript: A project cannot be used in two compilations at the same time. Create multiple projects with createProject instead #656

Open
chenzhutian opened this issue Sep 20, 2020 · 1 comment

Comments

@chenzhutian
Copy link

Expected behavior:
No error
When I run watch, I got the following error

Actual behavior:

[22:39:13] Error: gulp-typescript: A project cannot be used in two compilations at the same time. Create multiple projects with createProject instead.
at project (/Users/zhutian/Code/billofchen/node_modules/gulp-typescript/release/project.js:36:19)
at componentTS (/Users/zhutian/Code/billofchen/gulpfile.js:50:15)
at bound (domain.js:415:14)
at runBound (domain.js:428:12)
at asyncRunner (/Users/zhutian/Code/billofchen/node_modules/async-done/index.js:55:18)
at processTicksAndRejections (internal/process/task_queues.js:75:11)

Your gulpfile:

const tsProject = tsCompiler.createProject(path.join(__dirname, 'tsconfig-build.json'))

async function componentTS() {
    return tsProject.src()
        .pipe(sourcemaps.init())
        .pipe(tsProject())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(distPath))
}


function parallelWatch() {
    gulp.watch(
        [path.join(srcPath, '**/*.ts'), '!' + path.join(srcPath, '**/__test__/**')],
        { ignoreInitial: false },
        componentTS
    )
}

const watch = gulp.series(cleanDist, parallelWatch)

tsconfig.json

Include your tsconfig, if related to this issue.

{
    "compilerOptions": {
        "target": "ES6",
        "lib": ["ES6", "DOM"],
        "strictNullChecks": true,
        "noImplicitAny": false,
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "module": "CommonJS",
        "moduleResolution": "node",
        "allowJs": false,
        "experimentalDecorators": true,
        "noImplicitThis": true,
        "noImplicitReturns": true,
        "alwaysStrict": true,
        "inlineSourceMap": true,
        "inlineSources": true,
        "noFallthroughCasesInSwitch": true,
        "incremental": true,
        "strict": true,
        "removeComments": true,
        "pretty": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "allowSyntheticDefaultImports": true,
        "strictPropertyInitialization": true,

    },
    "include": ["./src/**/*.ts", "node_modules/miniprogram-api-typings/index.d.ts"]
}
@tillig
Copy link

tillig commented Sep 24, 2021

I got around this by creating the tsProject inside the Gulp task, which the docs say not to do... but it was the only thing I could find that stopped this error from happening. I only have the one build task that uses the tsProject and watch just calls that.

Note my Gulpfile is also in TypeScript, unclear if that makes a difference.

function build(): NodeJS.ReadWriteStream {
  const tsProject = typescript.createProject(path.join(taskName, 'tsconfig.json'));
  return tsProject
    .src()
    .pipe(eslint.default())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError())
    .pipe(tsProject(typescript.reporter.longReporter()))
    .js
    .pipe(gulp.dest((file) => {
      return file.base ?? process.cwd();
    }));
}

function watch(): FSWatcher {
  return gulp.watch(path.join('src', '**', '*.ts'), build);
}

exports.watch = gulp.series(build, watch);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants