Gulp rollup babel error - Cannot read property 'preserveSynlinks' / 'rollupVersion of undefined

Viewed 289

I'm trying to create a gulp task that will use Rollup to compile JavaScript files for modern and legacy using environment variables. I've introduced plugin-node-resolve and plugin-commonjs for the legacy side of things, however whenever I run the script for legacy I get the following error:

Message:\
    Cannot read property 'preserveSymlinks' of undefined\
Details:\
    code: PLUGIN_ERROR\
    hook: buildStart\
    domainEmitter: [object Object]\
    domainThrown: false

Note: I'm aware that the versions of rollup-plugin-babel, rollup-plugin-commonjs and rollup-plugin-node-resolve are deprecated. I've tried using the @rollup/ variants but when I use these, I get the following error so I must be missing something regardless:

Message:
    Cannot read property 'rollupVersion' of undefined
Details:
    domainEmitter: [object Object]
    domainThrown: false

Here are my files:

gulp task

const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const concat = require( 'gulp-concat');
const gulp = require('gulp');
const resolve = require('rollup-plugin-node-resolve');
const rollup = require( 'gulp-rollup');

const library = require('./library');


module.exports = () => {
    
    process.env.NODE_ENV = process.env.BROWSER;

        const rollupConfig = {
        allowRealFiles: true,
        input: library.getInputPath('scripts'),
        output: {'format': 'iife'},
        plugins: [
            babel()
        ],
        onwarn(warning, warn) {
            if (warning.code === 'THIS_IS_UNDEFINED') return;
            warn(warning);
        }
    };

    if (process.env.BROWSER === 'legacy') {
        rollupConfig.plugins = [
            ...rollupConfig.plugins,
            resolve({
                jsnext: true,
                main: true,
                browser: true
            }),
            commonjs(),
        ];
    }

    gulp.task('build:scripts', gulp.series('lint:scripts', () => {   
        const inputPath = library.getInputPath('scripts');
        const outputPath = library.getOutputPath('scripts');
        const outputFile = library.getFileName('scripts');

        return gulp.src(inputPath)
            .pipe(rollup(rollupConfig))
            .pipe(concat(outputFile))
            .pipe(gulp.dest(outputPath));
    }));
}

.babelrc:

{
    "exclude": "node_modules/**",
    "env": {
        "modern": {
            "plugins": [
                "@babel/plugin-proposal-class-properties"
            ]
        },
        "legacy": {
            "presets": [
                "@babel/preset-env"
            ],
            "plugins": [
                "@babel/plugin-proposal-class-properties"
            ]
        }
    }
}
0 Answers
Related