angular - 使用 http-server 激活服务器得到 TypeError: Readable.from is not a function
问题描述
我目前将 pwa 添加到我的新 Angular 项目中。
C:\Users\alan_yu\angular-pwa>http-server -p 8080 -c-1 dist/angular-pwa
Starting up http-server, serving dist/angular-pwa
http-server version: 14.0.0
http-server settings:
CORS: disabled
Cache: -1 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none
Available on:
http://192.168.16.91:8080
http://192.168.56.1:8080
http://192.168.99.1:8080
http://127.0.0.1:8080
Hit CTRL-C to stop the server
但是加载网页后我在控制台中遇到了错误:
[2021-10-21T06:51:39.582Z] "GET /" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
(node:11416) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
C:\Users\alan_yu\AppData\Roaming\npm\node_modules\http-server\lib\core\index.js:246
stream = Readable.from(bytes)
^
TypeError: Readable.from is not a function
at serve (C:\Users\alan_yu\AppData\Roaming\npm\node_modules\http-server\lib\core\index.js:246:29)
at C:\Users\alan_yu\AppData\Roaming\npm\node_modules\http-server\lib\core\index.js:419:13
at FSReqCallback.oncomplete (fs.js:149:5)
环境版本
操作系统类型:Windows 7 Pro
节点版本:V12.2.0
http服务器版本:V14.0.0
解决方案
stream.Readable.from
新增功能:node v12.3.0, v10.17.0
将节点从 V12.2.0 更新到 v13.13.0(至少 v12.3.0)后,http-server 运行良好。
参考:Node.js 文档
推荐阅读
- r - 如何使用 R 运行双循环
- amazon-web-services - 如何在 AWS SQS 中查看特定日期收到的消息?(或者今天最后一次收到)
- amazon-web-services - 移动应用程序中的 AWS AccessKeyId 和 SecretKey
- ruby-on-rails - 如何检查值是否在 CanCanCan 条件散列的数组中
- java - 列出一个类的所有字段,如果它们匹配所需的类型,则将它们放在一个列表中
- sql - SQL 一个字段计数其他字段的聚合
- node.js - Sequelize 5 属于关系不起作用
- c# - 定义一个“类型”类型的变量,它只接受作为特定类型的子类的类型
- node.js - React FormData() 显示正确的有效负载但收到 400 错误请求
- node.js - 构建后使用 gzip 的 Github Actions