简体   繁体   中英

Cannot find module created with Browserify

I use Browserify and Gulp to bundle JavaScript modules. I have one module which I generate with the following code:

browserify("./index.js", {
        standalone: "lib1"
      })
      .bundle()
      .pipe(source("lib1.js"))
      .pipe(gulp.dest('DEST'));

Index.js file contains the following code:

module.exports = require('./lib/lib1.js');

Then I have a second module which imports the previous one and works fine. I bundle the second module using the following code

browserify("./index.js", {
        standalone: "lib2"
      }).external('lib1')
      .bundle()
      .pipe(source("lib2.js"))
      .pipe(gulp.dest('DEST'));

If I import both modules in a browser I get an error in the second one indicating that it cannot find module lib1 . Does anyone have any idea what I'm doing wrong?

In the browser I import first lib1 and them lib2

<script src='lib1.js'></script>
<script src='lib2.js'></script>

I have fixed the problem with a downgrade of Gulp 4 to Gulp 3. This is not a satisfactory solution.

In Gulp 3 I use the following code to generate the second file:

browserify("./index.js", {
      standalone: "lib2"
    })
    .bundle()
    .pipe(source("lib2.js"))
    .pipe(gulp.dest('DEST'));

Using Gulp 3 I can import both libraries and it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM