numical/script-ext-html-webpack-plugin

Error: ScriptExtHtmlWebpackPlugin: no asset with href

DevNebulae opened this issue ยท 18 comments

Shouldn't the plugin be looking for something within its src tag?

It happened when I tried to inline a CoffeeScript source with the name animation.coffee, which gets transpiled to animation.js and in development mode, it will get renamed to animation.js?[hash]. Giving the file the async attribute works fine with the following regex: /animation\.*/. What goes wrong here?

Sorry, I'm not following. The async functionality does work ..? What does not?
Perhaps you could post a working and a failing config so I better understand what you are asking?
Thanks!

Sorry, I was talking about the inline functionality. For some reason, the regex works with async, but not with inline.

Also getting this error using the inline option.

Config is more or less:

entry: {
  // ...other bundles
  popout: path.resolve('src/popout/index.js')
}

plugins: [
  new HtmlWebpackPlugin({
    template: /* other */,
    chunks: ['bundle'],
    hash: true,
  }),
  new HtmlWebpackPlugin({
    template: path.resolve('src/popout/index.html'),
    filename: 'popout.html',
    chunks: ['popout'],
    hash: true,
  }),
  new ScriptExtHtmlWebpackPlugin({
    inline: 'popout',
    defaultAttribute: 'async',
  }),
]

May have something to do with using hash: true?

The error:

screen shot 2017-04-13 at 12 52 53 pm

I have the same problem in one project where inline: 'manifest' fails with the same error as @echenley gets and in another one it works flawlessly, inlining the manifest code. Haven't been figured out why that is yet..

@DevNebulae, @echenley
Sorry for the ridiculously long time to fix.
Probably too late for you but this is fixed on v1.7.2.

@mbohgard - the issue fixed wass StyleExt not coping with the HtmlWebpack option hash.
Is your issue the same? I'll close this issue on the assumption it is but if not please just raise another.

Closed as @mbohgard's issue assued to be the hash problem.

@numical Thanks for giving this a shot. I don't use the hash option with HtmlWebpack since I use the chunkhash feature of Webpack itself. The "no asset with href" error still occurs with the new patch.

@mbohgard - I'm not sure what your issue can be: chunkhash should be (!) supported. However I have put out a fix for someone else which might be related. Can you try the latest version 1.7.4? If that does not solve your problem, please raise a new issue with your webpack config detailed.

sorry to bother you,i got a same problem
is the reason of the problem that Because you set more than two of HtmlWebpackPlugin()?
01

02

03

albv commented

I've got the same error trying to inline webpack manifest. Here is minimal config to reproduce:

const path = require('path');

const root = path.join.bind(path, __dirname);
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');


module.exports = function (options) {
  return {
    entry: {
      'main': './src/index.js'
    },

    resolve: {
      extensions: ['.js', '.json'],
      modules: [root('src'), root('node_modules')],
    },

    output: {
      path: root('dist'),
      filename: '[name].bundle.js',
      sourceMapFilename: '[file].map',
      chunkFilename: '[id].chunk.js'
    },
   
    plugins: [
      new CommonsChunkPlugin({
        name: ['manifest'],
        minChunks: Infinity,
      }),

      new ScriptExtHtmlWebpackPlugin({
        inline: [/manifest/]
      }),

      new HtmlWebpackPlugin({
        chunksSortMode: 'dependency',
        inject: true
      }),
    ]
  };
}

I found that it's order of plugins that matters. If I put ScriptExtHtmlWebpackPlugin after HtmlWebpackPlugin all works as expected.

....   
    plugins: [
      new CommonsChunkPlugin({
        name: ['manifest'],
        minChunks: Infinity,
      }),

      new HtmlWebpackPlugin({
        chunksSortMode: 'dependency',
        inject: true
      }),

      new ScriptExtHtmlWebpackPlugin({
        inline: [/manifest/]
      }),
    ]
....

@numical is it a bug?

@albv From brief scanning, people have used the configuration you are using, but triggered the bug somehow. So yes, I would say that it is a bug.

if I set more than two of HtmlWebpackPlugin() , how to fixed this error ? @numical @definedw

albv commented

@zangcen try to put ScriptExtHtmlWebpackPlugin after the last of HtmlWebpackPlugin

Hi All,
SciptExt must be after HtmlWebpackPlugin in the configuration - plugin order does matter in Webpack.

I will make the README more explicit on this issue - sorry to those who have wasted time with this.

With regards to using multiple instances of HtmlWebpackPlugin, this is not yet a scenario that ScriptExt has been designed or tested for. If this is something you would find useful please raise an issue defining what you need and suggesting how you think this is best configured. Better still, create a PR! :-)

For ideas, take a look at how the sister plugin style-ext-html-webpack-plugin copes with this scenario.

albv commented

One more thing that could give you the "no asset with href" error... If you are using output.publicPath option it must ends with /. So for example /static/ will work, /static won't.

@albv - thanks! I had caught that on standard attributes but not resource hints. Fixed in v1.8.3.

Same here
publicPath: '/'
Error: Error: ScriptExtHtmlWebpackPlugin: no asset with href 'oembed.bundle.js'
plugin version: "script-ext-html-webpack-plugin": "^1.8.8"