【发布时间】:2020-11-22 14:09:21
【问题描述】:
我正在学习 Node.js,在入门课程中,我必须设置 node 和 npm。现在根据讲师的说法,在终端中键入“npm start”然后在 index.html 文件中进行更改后,浏览器应该会自动刷新选项卡以使更改生效,但在我的情况下,每次我做我必须手动刷新 Safari 选项卡才能看到更改。
请注意,我使用的是同一台机器,即本身没有服务器端和客户端。操作系统为 macOS Catalina 10.15.6。
请问有什么可能的解决办法吗?
谢谢
package.json 文件:
{
"name": "confusion",
"version": "1.0.0",
"description": "This is a website for Ristorante Con Fusion",
"main": "index.html",
"scripts": {
"start": "npm run lite",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server"
},
"author": "Raffay",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.5.4"
},
"dependencies": {
"bootstrap": "^4.5.0",
"jquery": "^3.5.1",
"nodemon": "^2.0.4",
"popper.js": "^1.16.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RaffaySajjad/conFusion.git"
},
"keywords": [
"conFusion"
],
"bugs": {
"url": "https://github.com/RaffaySajjad/conFusion/issues"
},
"homepage": "https://github.com/RaffaySajjad/conFusion#readme"
}
使用命令“nodemon”从终端启动 nodemon 会打印以下错误
raffaysajjad@192 ~ % cd /Users/raffaysajjad/Desktop/Full\ Stack\ Web\ Development\ \(React\ Specialization\)/Course\ 1\ \(Front-End\ WebUI\ Frameworks\ \&\ Tools\ -\ Bootstrap\ 4\)/Week\ 1/Exercise/conFusion
raffaysajjad@192 conFusion % nodemon
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: html,json
[nodemon] starting `node index.html`
/Users/raffaysajjad/Desktop/Full Stack Web Development (React Specialization)/Course 1 (Front-End WebUI Frameworks & Tools - Bootstrap 4)/Week 1/Exercise/conFusion/index.html:1
<!DOCTYPE html>
^
SyntaxError: Unexpected token '<'
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
[nodemon] app crashed - waiting for file changes before starting...
【问题讨论】:
-
我建议您为此使用 nodemon。
-
不过,我认为这可能只适用于您使用模板引擎时。如果你只是使用 Node 服务器端,你可以(正如其他人所说)使用 nodemon 以及 VSCode Live Server 之类的东西:marketplace.visualstudio.com/… 应该可以工作,但不是 100% 确定
标签: html node.js npm node-modules page-refresh