How to catch @rollup/plugin-typescript errors

Viewed 818

I use api rollup.watch(options) to build typescript.

By default @rollup/plugin-typescript will print an error message in the console if there is a compile error, but no file name and line number is printed, and watcher.on('event') does not trigger the error event.

I found that the option noEmitOnError: true triggers the error event in watcher.on('event'), but only the first time, the second time it throws an error and exit.

import rollupTypescript from '@rollup/plugin-typescript';

let options: rollup.RollupWatchOptions = {
    ...
    plugins: [
        rollupTypescript({
            noEmitOnError: true,
            tsconfig: path.join(__dirname, `tsconfig.json`),
        }),
    ],
};

let watcher = rollup.watch(options);

watcher.on('event', async (evt) => {
    if (evt.code === 'ERROR') {
        console.log(evt);
    }
});

version

  • rollup: 2.46.0
  • @rollup/plugin-typescript: 8.2.1

How do I safely catch the error?

0 Answers
Related