【发布时间】:2019-04-06 12:38:19
【问题描述】:
我的问题是为什么会显示这个错误?
src/app/p2p/p2p.component.ts(14,16) 中的错误:错误 TS2580:不能 找到名称“需要”。您需要为节点安装类型定义吗? 试试
npm i @types/node。
我已经安装了
@types/node
in app/tsconfig.app.json have add
"types": [
"node"
],
"typeRoots": [
"../node_modules/@types"
]
但是有错误找不到'require'
【问题讨论】:
-
显示你的 p2p.component.ts
-
声明 var 要求:任何;导出类 P2pComponent 实现 OnInit { constructor() { var Peer = require(peer) var p = new Peer({initiator: location.hash === '#1', 涓流: false }) p.on('signal', function (data) { console.log('SIGNAL', JSON.stringify(data)) document.querySelector('#outgoing').textContent = JSON.stringify(data) }) document.querySelector('form').addEventListener ('submit', function (ev) { ev.preventDefault()}) p.on('connect', function () { console.log('CONNECT') p.send('whatever' + Math.random() ) }) } }
标签: angular typescript angular7 typescript3.0