简体   繁体   English

Uncaught ReferenceError: require is not defined javascript 错误

[英]Uncaught ReferenceError: require is not defined javascript error

This question is very common one, however none of the solution had worked for me.这个问题很常见,但是没有一个解决方案对我有用。 I am trying to use "require" to file system module but I keep runnig to this error.我正在尝试对文件系统模块使用“require”,但我一直在运行这个错误。 Uncaught ReferenceError: require is not defined

const fs = require('fs');

I realize that I need to use browserify to get "require" to work on client side so I installed it but no luck.我意识到我需要使用 browserify 来让“要求”在客户端工作,所以我安装了它但没有运气。

Thanks everyone for your replies I figured that I didn't understand how to use Browserify.感谢大家的回复我想我不明白如何使用 Browserify。 I just had to compile my code with Browserify browserify main.js -o bundle.js , then link it to my html <script src="bundle.js"></script> (I am new to this obviously and my mind is blown now LOL).我只需要用 Browserify browserify main.js -o bundle.js编译我的代码,然后将它链接到我的 html <script src="bundle.js"></script> (显然我是新手,我的想法是现在吹大声笑)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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