Hey,
Whenever I try to import a plugin the build fails with this message:
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (758:0) while parsing /node_modules/gsap/ScrollTrigger.js while parsing file: /node_modules/gsap/ScrollTrigger.js
at DestroyableTransform.end [as _flush] (/node_modules/insert-module-globals/index.js:114:21)
If I only import 'gsap' it works perfectly.
Gulpfile.js:
const { watch, series, parallel, src, dest } = require('gulp')
const sourcemaps = require('gulp-sourcemaps')
const plumber = require('gulp-plumber')
const eslint = require('gulp-eslint')
const uglify = require('gulp-uglify')
const browserify = require('browserify')
const buffer = require('gulp-buffer')
const tap = require('gulp-tap')
const log = require('gulplog')
function buildScripts(cb) {
src('js/**/*.js')
.pipe(plumber())
.pipe(eslint())
.pipe(eslint.format())
.pipe(tap(function (file) {
log.info('bundling ' + file.path);
// replace file contents with browserify's bundle stream
file.contents = browserify(file.path, {
debug: true
})
.transform('babelify', {
presets: ['@babel/preset-env']
})
.bundle()
}))
// transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents)
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(dest('dist'))
cb()
}
If I import from 'gsap/dist/ScrollTrigger', then the build no longer fails. But then I am unable to register the plugin in browser and get this message:
Uncaught TypeError: n.gsap.registerPlugin(...) is not a function
at Object.1.gsap
The transpiled line that throws an error looks like so:
_gsap.gsap.registerPlugin(_ScrollTrigger.ScrollTrigger)(function () {
Any idea what is going on?
Thanks!