Webpack-dev-server: Uncaught TypeError: Cannot read property 'replace' of null

Created on 21 Jan 2016  路  22Comments  路  Source: webpack/webpack-dev-server

Hi, with version 1.14.1 I'm receiving this error:

Uncaught TypeError: Cannot read property 'replace' of null

I'm using an inline script in the index.html to load the .JS file (which is in the folder declared by publicPath) and I enabled the hot module replacement to receive updates.

Using version 1.14.0, it works fine (so at the moment I am not updating the webpack-dev-server module to 1.14.1).

Most helpful comment

Same problem here because of the Google Tag Manager script in the index.html

All 22 comments

I have the same situation as the OP. I also have a inline script which loads the bundle and I am getting the same error when I upgraded Webpack dev server to 1.14.1. Downgrade fixed the error, though.

Same problem, seems a problem with 1.14.1, 1.14.0 is alright.

I can confirm that it breaks when you have a script with no src tag. This is a showstopper if you have injected js into the html.

It breaks on this line: https://github.com/webpack/webpack-dev-server/blob/5b94506f0c47d7fd0bde8d215b6195450e71fc7e/client/index.js#L11

1.14.0 works for me too.

372 is a duplicate.

I'm getting the same error, downgrading to 1.14.0 temporarily as a work around.

Assuming the dev server script is the last script on the page seems to be the issue. https://github.com/webpack/webpack-dev-server/commit/3d3c000df8889e8b557995e5fe918b29072c377f

Same issue happened to me. Downgraded as well, works like a charm with 1.14.0

FYI: This is happening when you have a <script /> tag in your code that doesn't have a src attribute.

I was able to work around this with a hack-ish change:

<script>
    document.currentScript.src =''; // So that the script executes, but later has a src.

    // ... Do rest of work.   
</script>

I also have this issue. The sole script tag on my page contains a src attribute:

<script src="bundle.js"></script>

Downgrading to 1.14.0 solved the issue.

Same problem here because of the Google Tag Manager script in the index.html

This issue affected us as well. Fixing it required setting webpack-dev-server to 1.14.0 in package.json and then the running npm install again.

Same problem with 1.14.0

Just to point out for anyone else having the same issue -
For me this issue occurred because of using the Poper Blocker chrome extension. I didn't have no script tag without 'src' attribute in the page I was working on, so it was very confusing to understand that this extension injects a script tag (without an 'src' attribute) during the page loading.

I have disabled the extension until this issue will be fixed.

@idoco I can confirm that the popup blocker extension is causing the error for me. Not sure why that is though.

@adrianmc Yes, I think this is just because the extension injects a script tag with no 'src' attribute to the page which is the real root cause.

@idoco thanks!

My exact issue. Whitelisting the appropriate dev domains solves the issue.

Also getting this problem with the similar script injections. The solution provided above (downgrading to 1.14.0) works for me.

I had this error because of a 'defer' attribute in my script tag.

I had this issue when the variable I used was equal to null. Just added a check to perform .replace if not null, and it works now. Hope this helps someone.

Dupe of #117.

just for somebody rush into this issue:

i missed there is no correct entry in webpack config file after i git check out other branch

the webpack still watch old entry

faced the same issue. I just clear the cache data, it works.

yeah

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adiachenko picture adiachenko  路  3Comments

da2018 picture da2018  路  3Comments

mischkl picture mischkl  路  3Comments

mrdulin picture mrdulin  路  3Comments

hnqlvs picture hnqlvs  路  3Comments