babel / babelify

Browserify transform for Babel
MIT License
1.68k stars 114 forks source link

Really slow babelifying. #269

Closed japrogramer closed 6 years ago

japrogramer commented 6 years ago

Hello I don't understand why this piece of code is so slow, only a few files are passed to it. something like 13 files.


function specificJsx(file) {
  return browserify({
    entries: file,
    extensions: ['.jsx'],
    debug: true
  })
  .transform(babelify)
  .bundle()
  .on('error', (err) => {
    gutil.log('Browserify Error', gutil.colors.magenta(err.message))
  })
  .pipe(source('bundle.js'))
  .pipe(source(path.basename(file, '.jsx') + '.js'))
  .pipe(buffer())
  .pipe(sourcemaps.init({ loadMaps: true }))
  .pipe(sourcemaps.write(`${DEST_DIR}/js/maps`))
  .pipe(gulp.dest(`${DEST_DIR}/js`));
}
loganfsmyth commented 6 years ago

Define "so slow"? You haven't given us much to work with.

japrogramer commented 6 years ago

the console became unresponsive, I believe that the error is because of too many open files .. I lost my ssh session. when I try to run it locally i get these errors error.txt

[20:49:26] Browserify Error EMFILE: too many open files, open '/home/archangel/git/work/sixnexus/app/react_ui/node_modules/react-bootstrap/lib/utils/index.js'
[20:49:26] Browserify Error EMFILE: too many open files, open '/home/archangel/git/work/sixnexus/app/react_ui/node_modules/react-bootstrap/lib/utils/index.js'
/home/archangel/git/work/sixnexus/app/react_ui/node_modules/vinyl-buffer/index.js:12
    if (file.isNull()) return push(file, next)
             ^

TypeError: file.isNull is not a function
    at DestroyableTransform.write [as _transform] (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/vinyl-buffer/index.js:12:14)
    at DestroyableTransform.Transform._read (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Readable.ondata (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/readable-stream/lib/_stream_readable.js:619:20)
    at emitOne (events.js:116:13)
    at Readable.emit (events.js:211:7)
    at addChunk (/home/archangel/git/work/sixnexus/app/react_ui/node_modules/readable-stream/lib/_stream_readable.js:291:12)
loganfsmyth commented 6 years ago

If you leave out the .transform(babelify) line do you still get the error? The message itself doesn't necessarily seem Babel-related.

japrogramer commented 6 years ago

hmm ..

[21:10:21] Using gulpfile ~/git/work/sixnexus/app/react_ui/gulpfile.js
[21:10:21] Starting 'build'...
[21:10:21] Starting 'config'...
[21:10:21] Finished 'build' after 6.87 ms
[21:10:21] Finished 'config' after 15 ms
[21:10:21] Starting 'jsx'...
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
[21:10:21] Browserify Error 'import' and 'export' may appear only with 'sourceType: module'
japrogramer commented 6 years ago
   11 function specificJsx(file) {                                                                                                                                                                                                                                                                                                                                                                                                        
   10   return browserify({                                                                                                                                                                                                                                                                                                                                                                                                               
    9     entries: file,                                                                                                                                                                                                                                                                                                                                                                                                                  
    8     extensions: ['.jsx'],                                                                                                                                                                                                                                                                                                                                                                                                           
    7     debug: true                                                                                                                                                                                                                                                                                                                                                                                                                     
_   6   })                                                                                                                                                                                                                                                                                                                                                                                                                                
    5   .bundle()                                                                                                                                                                                                                                                                                                                                                                                                                         
    4   .on('error', (err) => {                                                                                                                                                                                                                                                                                                                                                                                                           
    3     gutil.log('Browserify Error', gutil.colors.magenta(err.message))                                                                                                                                                                                                                                                                                                                                                                
    2   })                                                                                                                                                                                                                                                                                                                                                                                                                                
    1   .pipe(buffer())                                                                                                                                                                                                                                                                                                                                                                                                                   
  35    .pipe(gulp.dest(`${DEST_DIR}/js`));                                                                                                                                                                                                                                                                                                                                                                                               
    1 }  
loganfsmyth commented 6 years ago

Alright, if you need Babel to compile the code properly then it's hard to test :P Browserify doesn't know what an import is.

Is this a new issue, or is this an existing codebase that you've notices is slow recently or something?

japrogramer commented 6 years ago

I made some changes to make that last error go away but now im back to the original error

$ npm install babel-preset-es2015

and in gulpfile set:
.transform(["babelify",{presets: ["es2015"]}])
japrogramer commented 6 years ago

hmm... I upgraded nodejs maybe that will fix it

japrogramer commented 6 years ago

nope, here is my package.json

▶ cat package.json
{
  "name": "react_ui",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "dependencies": {
    "bootstrap": "^3.3.7",
    "debounce": "^1.1.0",
    "font-awesome": "^4.7.0",
    "jquery": "^3.2.1",
    "leaflet": "^1.1.0",
    "lodash": "^4.17.4",
    "moment": "^2.18.1",
    "prop-types": "^15.6.0",
    "query-string": "^5.0.0",
    "react": "^15.6.1",
    "react-bootstrap": "^0.31.5",
    "react-dom": "^15.6.1",
    "react-ga": "^2.2.0",
    "react-leaflet": "^1.4.0",
    "react-overlays": "^0.8.3",
    "react-select": "^1.0.0-rc.5",
    "react-simple-dropdown": "^3.0.0",
    "react-table": "^6.7.4",
    "sass-spacing": "^2.0.0",
    "superagent": "^3.5.2"
  },
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babelify": "^7.3.0",
    "browserify": "^14.4.0",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^15.0.1",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^5.0.3",
    "eslint-plugin-react": "^7.1.0",
    "glob": "^7.1.2",
    "gulp": "^3.9.1",
    "gulp-babel": "^6.1.2",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "gulp-sourcemaps": "^2.6.0",
    "gulp-util": "^3.0.8",
    "merge": "^1.2.0",
    "merge-stream": "^1.0.1",
    "node-sass": "^4.6.0",
    "run-sequence": "^1.2.2",
    "vinyl-buffer": "^1.0.0",
    "vinyl-source-stream": "^1.1.0"
  },
  "scripts": {
    "package": "gulp build --env=production",
    "dev": "gulp build --env=development && gulp watch --env=development",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}
loganfsmyth commented 6 years ago

For EMFILE it's probably best to increase your file descriptor limit and see if that helps. It's not an uncommon issue with Browserify really, but not Babel-specific: https://www.google.com/search?q=browserify+emfile Something like https://github.com/browserify/browserify/issues/1003#issuecomment-65963297 is worth trying.

japrogramer commented 6 years ago

I tried .. and it is still not enough. ulimit -n 4096

japrogramer commented 6 years ago

Maybe its this line

    const COMPONENTS = glob.sync('src/components/**/*.jsx'); 
  8 gulp.task('jsx', () => {                                                                                                                                                                                                                                                                                                                                                                                                            
    7   return merge(COMPONENTS.map((f) => specificJsx(f)))                                                                                                                                                                                                                                                                                                                                                                               
    6 });                                                                                                                                                                                                                                                                                                                                                                                                                                 
    5    

I think that is making all the things happen in parallel. so how can I change that line to be linear.

japrogramer commented 6 years ago

Im trying this .. I still get the error but now it also prints that it completed successful.

    5 gulp.task('jsx', () => {                                                                                                                                                                                                                                                                                                                                                                                                            
~   4   const gather = [];                                                                                                                                                                                                                                                                                                                                                                                                                
+   3   COMPONENTS.forEach((f) => {                                                                                                                                                                                                                                                                                                                                                                                                       
+   2     gather.push(specificJsx(f));                                                                                                                                                                                                                                                                                                                                                                                                    
+   1     setTimeout(function() {                                                                                                                                                                                                                                                                                                                                                                                                         
+ 25      }, 500)                                                                                                                                                                                                                                                                                                                                                                                                                         
+   1   });                                                                                                                                                                                                                                                                                                                                                                                                                               
+   2   return gather                                                                                                                                                                                                                                                                                                                                                                                                                     
    3 });                                                                                                                                                                                                                                                                                                                                                                                                                                 
    4