typescript 如何在 Visual Studio Code 中设置本地 Web 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47908158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set local web server in Visual Studio Code
提问by saranchel n
I am new in VS code and working in typescript.Just I am trying to set local server path to open my HTML file.how to set that and when I was trying to set always I am getting error. I can not use this (NPM install) and (NPM start) command in terminal.If I use this command I am getting error. Any proxy issue? How to resolve this issue in VS code?
我是 VS 代码的新手,并在打字稿中工作。只是我想设置本地服务器路径来打开我的 HTML 文件。如何设置,当我尝试设置时总是出现错误。我无法在终端中使用此(NPM 安装)和(NPM 启动)命令。如果我使用此命令,则会出现错误。任何代理问题?如何在 VS 代码中解决此问题?
Folder structure:
文件夹结构:
TsDemo--folder name
.vscode
->launch.json
->tasks.json
out
->app.js
->app.js.map
app.ts
index.html
tsconfig.json
i follwed this link:https://blogs.msdn.microsoft.com/cdndevs/2016/01/24/visual-studio-code-and-local-web-server/but not working. If I use this command: D:\TsDemo>NPM install
我关注了这个链接:https://blogs.msdn.microsoft.com/cdndevs/2016/01/24/visual-studio-code-and-local-web-server/ 但没有工作。如果我使用这个命令:D:\TsDemo>NPM install
D:\TsDemo>npm install
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/lite-server failed, reason: connect ETIMEDOUT 10.232.192.45:8080
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\AppData\Roaming\npm-cache\_logs17-12-20T14_16_49_680Z-debug.log
If I use this command: D:\TsDemo>NPM start
如果我使用这个命令:D:\TsDemo>NPM start
D:\TsDemo>npm start
>[email protected] start D:\TsDemo
> npm run lite
npm WARN invalid config loglevel="notice"
> [email protected] lite D:\TsDemo
>lite-server --port 10001
'lite-server' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] lite: `lite-server --port 10001`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] lite script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users1732\AppData\Roaming\npm-cache\_logs17-12-20T14_07_41_636Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `npm run lite`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\AppData\Roaming\npm-cache\_logs17-12-20T14_07_41_694Z-debug.log
回答by k.vincent
Just use the Live Server Extension. Install it from VS Code directly and you will be fine. You'll then have a link in the bottom of your editor to start and run the server automatically and also view your HTML immediately.
只需使用 Live Server Extension。直接从 VS Code 安装它,你会没事的。然后,您将在编辑器底部有一个链接,用于自动启动和运行服务器,并立即查看您的 HTML。
Also check: live-server-web-extensionand Live Server