简体   繁体   中英

can not find file file.js with browserify

I'm facing some issue while using the browserify js file.

Here is my index.js file:

module.exports = require('./lib/clients/test/client');

my browserify bundle command:

browserify -r ./index.js > bundle.js

Here is my html file where i am using the above generated bundle.js file:

<html>
<head>
    <title></title>
</head>
<body>
<script src='bundle.js'>
</script>
<script>
var x = require('./index.js');
</script>
</body>
</html>

I'm seeing the following error when trying to load html file:

Uncaught Error: Cannot find module './index.js'. 

I have cross verified with the stack overflow answers on the same error and tried the solutions still its not working for me. please correct where i am worng.

its working after changing the

var x = require('./index.js'); to var x = require('/index.js');

in html file.

i have observed that in bundle file its being saved as '/index.js'.

thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM