【问题标题】:Watchify - Uncaught ReferenceError: require is not definedWatchify - 未捕获的 ReferenceError:未定义要求
【发布时间】:2019-09-28 12:51:51
【问题描述】:

我需要 Node.js 功能,如我的 javascript 代码中的 require() 函数,所以我使用 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)然后监视(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>

那我该怎么办?

【问题讨论】:

标签: javascript git require watchify


【解决方案1】:

Watchify 会创建一个捆绑文件,其中包含处理了 require()s 的所有代码。

这不会使require() 在您的原始代码中工作;你应该只在你的 HTML 页面中包含这个包,而不是原始的 JS 文件。

【讨论】:

    猜你喜欢
    • 2020-05-16
    • 2012-12-16
    • 2017-02-28
    • 2017-06-01
    • 2018-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多