TypeError: mime.lookup is not a function

2,033 views
Skip to first unread message

Qu Yongqiang

unread,
Mar 8, 2018, 4:42:13 AM3/8/18
to weinre
weinre --httpPort 8088
2018-03-08T09:38:31.706Z weinre: starting server at http://localhost:8088
/usr/local/lib/node_modules/weinre/node_modules/._connect@1.9.2@connect/lib/middleware/static.js:143
    type = mime.lookup(path);
                ^

TypeError: mime.lookup is not a function

After I started the weinre, when access http://localhost:8088 from broswer, it errors.

Qu Yongqiang

unread,
Mar 8, 2018, 4:45:53 AM3/8/18
to weinre
* `lookup()` renamed to `getType()`
in the readme of mime
## Version 2 Notes

Version 2 is a breaking change from 1.x as the semver implies.  Specifically:

* `lookup()` renamed to `getType()`
* `extension()` renamed to `getExtension()`
* `charset()` and `load()` methods have been removed





Qu Yongqiang

unread,
Mar 8, 2018, 4:51:36 AM3/8/18
to weinre
I have solved this problem by myself!

step 1 
change file : node_modules/._connect@1.9.2@connect/lib/middleware/static.js:143
from 
var charset = mime.lookup(type);
to 
var charset = mime.getType(type);


step 2
change file: node_modules/._connect@1.9.2@connect/lib/middleware/static.js:167
from 
 var charset = mime.charsets.lookup(type);

to 
 var charset = mime.getType(type);

Patrick Mueller

unread,
Mar 10, 2018, 10:08:41 PM3/10/18
to weinre
How did you install weinre?  I don't get a directory tree that includes `node_modules/._connect@1.9.2@connect/lib/middleware/static.j`.  When I run `npm install -g weinre`, I get `/usr/local/lib/node_modules/weinre/node_modules/express/node_modules/connect/lib/middleware/static.js`

felix...@gmail.com

unread,
Apr 10, 2018, 2:46:02 AM4/10/18
to weinre
这个太坑了,API变化之后依赖居然不能用了,WTF!!
居然还要自己去改源码才能取让它正常工作。bullshit!!

felix...@gmail.com

unread,
Apr 10, 2018, 2:48:03 AM4/10/18
to weinre
But, thank you for your advice. @Qu
Message has been deleted

Philip Murphy

unread,
Jun 27, 2018, 10:46:20 AM6/27/18
to weinre
Awesome fix. BTW, for me the file in question was located in weinre\node_modules\connect\lib\middleware\static.js

To get to work I did the following:

cd c:\apps (where I store my apps)
mkdir weinre
cd weinre
npm i weinre
edit weinre\node_modules\connect\lib\middleware\static.js and make changes as directed.
cls && node C:\apps\weinre\node_modules\weinre\weinre --boundHost my-ip-address --httpPort 443 < Nul (note: I run this on 443 due to firewall restrictions)

Insert the following into the top of your index.html (changing my-ip-address to your local web server ip address)

<!-- Required for weinre debugging. -->
<script type="text/javascript">

// Get over issue where some styles are not being displayed when debugging with weinre.
function whackWebkitMatchesSelector() {
var oldMatches = Element.prototype.webkitMatchesSelector;

function newMatches(selector) {
try {
return oldMatches.call(this, selector);
}
catch (err) {
return false;
}
}

Element.prototype.webkitMatchesSelector = newMatches;
}

whackWebkitMatchesSelector();
</script>


Load your app and then visit http://my-ip-address:443

BTW, the last issue I was able to solve with this was finding out that my old S3 running Android 4.4.3 didn't have a String.startsWith method implemented. Needed to polyfill (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith for further details). This is required for ReactJs to work properly.



Reply all
Reply to author
Forward
0 new messages