0

I'm using gulp 4 in my project with bootstrap 5 when I call the BS from node_modules the js did not work as I expected it show me this error message in my console.

Uncaught ReferenceError: require is not defined

here is my app.js file:

var bootstrap = require("../../node_modules/bootstrap/dist/js/bootstrap.bundle");

here is my gulpfile.js file:

const { src, dest, watch, series, parallel } = require("gulp");
const terser = require("gulp-terser");
const babel = require("gulp-babel");
const browsersync = require("browser-sync").create();

...

function compileJS() {
    return src("src/js/app.js", { sourcemaps: true })
        .pipe(babel())
        .pipe(terser())
        .pipe(dest("src/assets/js", { sourcemaps: "." }));
}

...

the SASS files work well but the js no I got that error message.

3
  • require is only available when running code in Node.js. Commented Apr 25, 2021 at 12:38
  • I find that I can use require in my js file by using something called babelify and browserify but I don't know how to implement it in my project. Commented Apr 25, 2021 at 12:40
  • 1
    I cannot help you with that and I'm not interested enough to investigate that for you. Commented Apr 25, 2021 at 12:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.