Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require fs-js in browser does not work after creating and including Bundle #2060

Open
gintares opened this issue May 6, 2023 · 1 comment

Comments

@gintares
Copy link

gintares commented May 6, 2023

package
https://www.npmjs.com/package/fs-js?activeTab=code

I downloaded source and map from :
https://cdn.jsdelivr.net/npm/fs-js@1.0.6/index.min.js
https://cdn.jsdelivr.net/sm/371e7d4afc5f7cd968f336bfe709890d019ca103eb9566a6ff3639d97efcefe0.map

I used browserify to create bundle
$ browserify -r fs-js ./fs.min.js > fsbund.js

in browser there is window on-load function to load all files, i.e. istart test.js when everything is loaded:

<script type="text/javascript" src="/js/fs.min.js"></script> <script type="text/javascript" src="/js/fsbund.js"></script> <script type="text/javascript" src="/js/test.js"></script>

I am getting error,

Uncaught ReferenceError: require is not defined
    at jsdelivr-header.js:1:1

where said contains this content:

/**
 * Minified by jsDelivr using UglifyJS v3.0.24.
 * Original file: /npm/fs-js@1.0.6/index.js
 * 
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */

test.js

var fs = require('fs-js'); 
var ckpdf = fs.open('/js/browserjs_test.txt', 'r', (err,fd) => {
    console.log(fd);
}); 

source, fs.min.js

var fs=require("fs");module.exports=fs;
//# sourceMappingURL=fs.js.map

map, fs.js.map

{"version":3,"sources":["jsdelivr-header.js","/npm/fs-js@1.0.6/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,IAAI,GAAK,QAAQ,MAEjB,OAAO,QAAU","file":"/npm/fs-js@1.0.6/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using UglifyJS v3.0.24.\n * Original file: /npm/fs-js@1.0.6/index.js\n * \n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var fs = require('fs');\r\n\r\nmodule.exports = fs;"]}
@ljharb
Copy link
Member

ljharb commented May 6, 2023

fs can't work in the browser, because there's no filesystem there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants