jonkemp / useref

Parse build blocks in HTML files to replace references
MIT License
51 stars 13 forks source link

TypeError: Cannot read property 'replace' of undefined #17

Open ghost opened 7 years ago

ghost commented 7 years ago

gulpfile.babel.js:

import gulp from 'gulp';
import useref from 'useref';
import browserSync from 'browser-sync';
import {create} from 'browser-sync';

const bs = create();

gulp.task('default',()=>{
  bs.init({
    server:{
      baseDir:'./'
    }
  })
})

gulp.task('demo',()=>{
  gulp.src('./src/css-practice/index.html')
  .pipe(useref())
  .pipe(gulp.dest('./dist'))
})

file ./src/css-practice/index.html with a sample content:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>css</title>
  </head>
  <body>
    sdasd
  </body>
</html>

cmd:

gulp demo

then get error:

TypeError: Cannot read property 'replace' of undefined
    at module.exports (/Users/xuxuewen/workspace/coding/com.andy.train/node_modules/useref/lib/getBlocks.js:31:19)
    at module.exports (/Users/xuxuewen/workspace/coding/com.andy.train/node_modules/useref/index.js:8:16)
    at Gulp.<anonymous> (/Users/xuxuewen/workspace/coding/com.andy.train/gulpfile.babel.js:28:9)
    at module.exports (/Users/xuxuewen/workspace/coding/com.andy.train/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/xuxuewen/workspace/coding/com.andy.train/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/xuxuewen/workspace/coding/com.andy.train/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/xuxuewen/workspace/coding/com.andy.train/node_modules/orchestrator/index.js:134:8)
    at /Users/xuxuewen/.nvm/versions/node/v6.10.2/lib/node_modules/gulp/bin/gulp.js:129:20
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
jonkemp commented 7 years ago

Use the gulp plugin rather than this module. That should fix it.