我需要require()在我的javascript代码中使用类似于函数的Node.js功能,因此我正在使用watchify,但是Uncaught ReferenceError: require is not defined at jsfile.js:3尽管watchify将代码捆绑并检查到bundle.js文件中,但它仍然给我带来错误,如果我在localhost上进行测试,一切都会变得更加容易,但是我已经将我的网站托管在heroku中,我不知道命令队列,我应该先执行git命令(git add . git commit -m "commit" git push heroku master),然后执行watchify(npm run watch)还是首先执行watchify而不是git命令?还是其他地方有问题?这是我的package.json代码(部分)"scripts": { "start": "node ilia.js", "watch": "npx watchify ./public/jsfile.js -o ./public/bundle.js"},"devDependencies": { "watchify": "^3.11.1"}和链接我的html中的javascript文件(bundle.js,jsfile.js)<script src="jsfile.js"></script><script src="bundle.js"></script>所以我该怎么做?
1 回答

肥皂起泡泡
TA贡献1829条经验 获得超6个赞
Watchify创建一个捆绑文件,其中包含require()
处理了您的所有代码。
那不能require()
在您的原始代码中起作用;您只应在HTML页面中包含该捆绑包,而不能在原始JS文件中添加该捆绑包。
添加回答
举报
0/150
提交
取消